Exercises on basic structures

  1. Make a dataframe called exam_rates from the following vectors:
name=c("Marie", "Gianni", "Silvia", "Laura","Mariachiara", "Simone", "Sarah", "Francesca", "Matteo")

id=c(8452, "AE12", 6732, "AS54", "GF49", 9328, "DS34", 3476, 7628)

pointsTest1=c(12, 15, 14, 5, 18, 3, 10, 7, 16)
  
pointsTest2=c(10, 9, 10, 7, 10, 3, 9, 8, 1)

pointsTest3=c(1, 2, 2, 2, 2, 1, 1, 0, 0)
exam_rates=cbind.data.frame(name, id, pointsTest1, pointsTest2, pointsTest3)

  1. Create a new column score containing sum of pointsTest1, pointsTest2 and pointsTest3 columns and a column average with the mean of these 3 columns. Hint: see functionalities of rowSums(), colSums(), rowMeans() and colMeans().
exam_rates$score=rowSums(exam_rates[, c("pointsTest1", "pointsTest2", "pointsTest3")])
exam_rates$average=rowMeans(exam_rates[, c("pointsTest1", "pointsTest2", "pointsTest3")])

  1. Create a new logical column passed containing TRUE if the score is >17 and FALSE otherwise. Hint: remember the theoretical part on logical vectors.
exam_rates$passed=exam_rates$score>17

  1. Evaluate how many people has a certain score. How many people has obtained the same score? Hint: use table( ) function.
table(exam_rates$score)
## 
##  7 14 15 17 20 23 26 30 
##  1  1  1  1  1  1  2  1

  1. Create a new dataframe exam_rates2 by selecting from the previous dataframe only people that passed the exam and columns name,pointsTest1,pointsTest2 and pointsTest3
exam_rates2=subset(exam_rates, passed)[, c("name","pointsTest1","pointsTest2", "pointsTest3" )]

  1. Melt the dataframe and reassign it to exam_rates2. Inspect the structure of the dataframe. What happened?
exam_rates2=reshape2::melt(exam_rates2)
## Using name as id variables

  1. Create a vector vec by extracting value column from the dataset exam_rates2. Then evaluate sum, mean, standard deviation, summary and quantiles of the vector. Hint: use sum( ), mean( ), sd( ), summary() and quantile() functions. Take some time to inspect results
vec<-exam_rates2$value

sum(vec)
## [1] 125
mean(vec)
## [1] 8.333333
sd(vec)
## [1] 5.498918
summary(vec)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   2.000  10.000   8.333  11.000  18.000
quantile(vec)
##   0%  25%  50%  75% 100% 
##    1    2   10   11   18

  1. Create a list collection that contains exam_rates, exam_rates2, vec and the quantiles of vec.
collection=list(exam_rates, exam_rates2, vec,  quantile(vec))

  1. Give a name to each element of the list.
names(collection)=c("Full", "Manipulated", "vector", "quantile")

  1. Create a matrix student_marks by binding following vectors as rows.
Marie=c(28, 29, 30, 27, 30)
Gianni=c(18, 19, 21, 26, 28)
Silvia=c(23, 24, 26, 30, 22)
Laura=c(30,29, 30, 28, 29)
Mariachiara=c(29, 30, 28, 27, 25)
Simone=c(24, 29, 30, 22, 19)
Sarah=c(26, 28, 25, 29, 30)
Francesca=c(18, 26, 28, 19, 26)
Matteo=c(26, 28, 30, 30, 28)
student_marks=rbind(Marie, Gianni, Silvia, Laura, Mariachiara, Simone, Sarah, Francesca, Matteo)

  1. Give column names to the matrix: CourseA, CourseB, CourseC, CourseD, CourseE
colnames(student_marks)=c("CourseA", "CourseB", "CourseC", "CounseD", "CourseE")

  1. Add the matrix to the collection list and name it. Hint: remember how to concatenate lists; lists can also contain one single element
student_marks=list(student_marks=student_marks)
collection=c(collection,student_marks)

  1. You have the following vector with ages of the students:
age=c(21, 24, 22, NA, NA, 20, 23, NA, NA)
names(age)=c("Marie", "Gianni", "Silvia", "Laura", "Mariachiara", "Simone", "Sarah", "Francesca", "Matteo")
  • extract names of people for which age information is missing
  • extract names of people for which age information is available
  • Assign to missing value in the vector the mean of available values. Hint: to do this task you can select only non NA values or explore parameters in mean() function. Try in both ways!
  • Using grep or grepl functions extract ages of people with “ia” in their names.
names(age[is.na(age)])
## [1] "Laura"       "Mariachiara" "Francesca"   "Matteo"
names(age[!is.na(age)])
## [1] "Marie"  "Gianni" "Silvia" "Simone" "Sarah"
mean(age[!is.na(age)])
## [1] 22
mean(age, na.rm = T)
## [1] 22
age[is.na(age)]<-mean(age, na.rm = T)
age[grep("ia", names(age))]
##      Gianni      Silvia Mariachiara 
##          24          22          22
age[grepl("ia", names(age))]
##      Gianni      Silvia Mariachiara 
##          24          22          22

  1. Consider the following dataframe:
info=cbind.data.frame(name=c("Marie", "Gianni", "Silvia", "Laura", "Mariachiara", "Simone", "Sarah", "Francesca", "Matteo"),
                       goes_to_gym=c(TRUE, TRUE, FALSE, NA, FALSE, NA, FALSE, TRUE, TRUE),
                       times_gym= c(3, NA,0, NA,0,NA, 0, NA, 5 ),
                       likes=c("ski", "snowboard", "pilates", "football", "tennis", "basketball", "tennis", NA, NA))
  • Extract people that have missing values in goes_to_gym
  • Extract people that have missing values in times_gym
  • Extract people that have missing values in likes
  • Extract people for which all informations are available. Do this task both using subset function and conditions into [ ]
info[is.na(info$goes_to_gym),]
##     name goes_to_gym times_gym      likes
## 4  Laura          NA        NA   football
## 6 Simone          NA        NA basketball
info[is.na(info$times_gym),]
##        name goes_to_gym times_gym      likes
## 2    Gianni        TRUE        NA  snowboard
## 4     Laura          NA        NA   football
## 6    Simone          NA        NA basketball
## 8 Francesca        TRUE        NA       <NA>
info[is.na(info$likes),]
##        name goes_to_gym times_gym likes
## 8 Francesca        TRUE        NA  <NA>
## 9    Matteo        TRUE         5  <NA>
subset(info, !is.na(goes_to_gym) & !is.na(times_gym) & !is.na(likes))
##          name goes_to_gym times_gym   likes
## 1       Marie        TRUE         3     ski
## 3      Silvia       FALSE         0 pilates
## 5 Mariachiara       FALSE         0  tennis
## 7       Sarah       FALSE         0  tennis
info[!is.na(info$goes_to_gym) & !is.na(info$times_gym) & !is.na(info$likes), ]
##          name goes_to_gym times_gym   likes
## 1       Marie        TRUE         3     ski
## 3      Silvia       FALSE         0 pilates
## 5 Mariachiara       FALSE         0  tennis
## 7       Sarah       FALSE         0  tennis

  1. Make a list info that contains the following elements (l, hour,station and mt ). Be sure to assign names to the elements.
l=cbind.data.frame(Date=c("03-04", "03-05", "03-06", "03-07", "03-08", "03-09", "03-10", "03-11", "03-12"),
                   Temp=c(12,5,18, 20, 12, 15, 17, 15, 19))


hour=c(12, 4, 14, 11, 13, 16, 12.30, 20, 13.30 )


station=c(rep("Saluzzo(CN)", 2), rep("Montecatini(PT)", 3),"Pescia(PT)", rep("Milano(MI)", 3))


mt=rbind(c(13,12,35), c(2.6, 6.2, 9), seq(30, 50, 6.7))
info=list(l, hour, station, mt)
names(info)=c("l", "hour", "station", "mt")

Without extracting elements from the list modify them with the following steps (you cannot use the original objects but only those in the list):

  • Assign to hour vector names by using values in the Temp column of the dataframe l

  • Transform station in a factor vector fixing levels that correspond to the alphabetical order of the cities

  • Add a column in l that contains values in station

  • Assign to hour an attribute station containing character values of station. Notice that I said character, not factor

  • Order station vector

  • Add to the list another vector New containing Temp values extracted matching station and the new column you added to the data frame (keep only the first element)

  • Evaluate if in the Temp column there are values in the range 19:40

  • Extract the indexes of the elements that are equal to 15 in hour

  • Create a new logical vector by evaluating in station the cities that are not in the “PT” province. Hint: explore the paramenters of the function you will use. Then add this vector to the list

  • How many elements does your list contain?

  • Create a new matrix mt2 of the same dimensions as mt that contains mt values if they are minor than 10 and mt values +1 if they are major or equal to 10. Add this to the list.

  • Using only a combination of [[ ]] and [ ] extract the second element of the fifth element of the list

  • Extract the second column of the mt matrix from the list

  • Extract all elements, except the second, of the list

  • Extract the data frame contained into the list and assign it to a variable data_frame

  • Subset data_frame by keeping only data for the stations “Milano(MI)” and “Saluzzo(CN)” and reassign it to the variable data_frame

  • Concatenate data_frame with the following dataframe data2 and reassign the result to data_frame

data2=cbind.data.frame(Date=c("03-07", "03-08", "03-09", "03-10", "03-11", "03-12", "03-04", "03-05", "03-06", "03-09", "03-10", "03-11", "03-12"),
                   Temp=c(11, 12, 14, 9, 8, 13, 14, 15, 6, 10, 18,14, 13),
                   station=c(rep("Milano(MI)", 6), rep("Saluzzo(CN)",7)))
  • Using table() evaluate how many times a certain Temp is retrieved in each city
  • Using dcast expand the data frame using as reference columns Date and station (reassign to data_frame)
  • Assign as rownames values in the column Date
  • Remove the column Date from the dataframe
  • Transform the dataframe into a matrix
  • Identify names of rows in which Milano and Saluzzo have the same values
  • Tranform the matrix by substituting “a” to values equal to 13. What happens to the matrix? Evaluate str() and typeof()
  • What happens if you try evaluating which elements are >10?
names(info$hour)=info$l$Temp

info$station=factor(info$station, levels=c("Milano(MI)","Montecatini(PT)","Pescia(PT)","Saluzzo(CN)"))

info$l$station=info$station

attr(info$hour, "station")=as.character(info$station)

info$station=info$station[order(info$station)]

info$New=info$l$Temp[match(info$station, info$l$station)] # notice that you can add directly an element using $

info$l$Temp%in%19:40
## [1] FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE
which(info$hour==15)
## named integer(0)
v=info$station[grep("(PT)", info$station, invert = T)]

info=c(info, list(v))

length(info)
## [1] 6
mt2=info$mt+(info$mt>=10)

info$mt2=mt2

info[[5]][2]
## [1] 17
info$mt[,2]
## [1] 12.0  6.2 36.7
info[-2]
## $l
##    Date Temp         station
## 1 03-04   12     Saluzzo(CN)
## 2 03-05    5     Saluzzo(CN)
## 3 03-06   18 Montecatini(PT)
## 4 03-07   20 Montecatini(PT)
## 5 03-08   12 Montecatini(PT)
## 6 03-09   15      Pescia(PT)
## 7 03-10   17      Milano(MI)
## 8 03-11   15      Milano(MI)
## 9 03-12   19      Milano(MI)
## 
## $station
## [1] Milano(MI)      Milano(MI)      Milano(MI)      Montecatini(PT)
## [5] Montecatini(PT) Montecatini(PT) Pescia(PT)      Saluzzo(CN)    
## [9] Saluzzo(CN)    
## Levels: Milano(MI) Montecatini(PT) Pescia(PT) Saluzzo(CN)
## 
## $mt
##      [,1] [,2] [,3]
## [1,] 13.0 12.0 35.0
## [2,]  2.6  6.2  9.0
## [3,] 30.0 36.7 43.4
## 
## $New
## [1] 17 17 17 18 18 18 15 12 12
## 
## [[5]]
## [1] Milano(MI)  Milano(MI)  Milano(MI)  Saluzzo(CN) Saluzzo(CN)
## Levels: Milano(MI) Montecatini(PT) Pescia(PT) Saluzzo(CN)
## 
## $mt2
##      [,1] [,2] [,3]
## [1,] 14.0 13.0 36.0
## [2,]  2.6  6.2  9.0
## [3,] 31.0 37.7 44.4
data_frame=info$l

data_frame=subset(data_frame, station%in%c("Milano(MI)","Saluzzo(CN)"))

data_frame=rbind.data.frame(data_frame, data2)

table(data_frame$Temp, data_frame$station)
##     
##      Milano(MI) Montecatini(PT) Pescia(PT) Saluzzo(CN)
##   5           0               0          0           1
##   6           0               0          0           1
##   8           1               0          0           0
##   9           1               0          0           0
##   10          0               0          0           1
##   11          1               0          0           0
##   12          1               0          0           1
##   13          1               0          0           1
##   14          1               0          0           2
##   15          1               0          0           1
##   17          1               0          0           0
##   18          0               0          0           1
##   19          1               0          0           0
data_frame=reshape2::dcast(data_frame, Date~station, value.var = "Temp")
## Aggregation function missing: defaulting to length
rownames(data_frame)=data_frame$Date

data_frame$Date<-NULL

data_frame=as.matrix(data_frame)

rownames(data_frame)[data_frame[,1]==data_frame[,2]]
## [1] "03-09"
data_frame[data_frame==13]="a"

data_frame>10
##       Milano(MI) Saluzzo(CN)
## 03-04      FALSE        TRUE
## 03-05      FALSE        TRUE
## 03-06      FALSE       FALSE
## 03-07      FALSE       FALSE
## 03-08      FALSE       FALSE
## 03-09      FALSE       FALSE
## 03-10       TRUE       FALSE
## 03-11       TRUE       FALSE
## 03-12       TRUE       FALSE

  1. Create a dataframe df1 using the vectors samples, genes and expression_counts (binding by columns) and an other dataframe df2 using vectors FOXA1, MYC, AR, ENSG00000281133, FAM138A (binding by rows). Assign the following colnames to df2: gene_name, gene_type, gene_id.

    Then:

    • add to df1 colums gene_id and gene_type by taking the information in df2
    • extract the unique names of the protein coding genes from df1
    • create a vector cases by grepping from df1 the string “MOD” and keeping only unique values
    • create a vector controls by grepping from df1 the string “NORM” and keeping only unique values
    • assign name “case” to all the elements in cases vector
    • assign name “control” to all the elements in controls vector
    • create a new vector samples by concatenating cases and controls
    • add a column annotation to df1 in which you have to put “case” and “control” values by matching the column samples in df1 with values in the vector samples
samples=c(rep("MOD01",5), 
          rep("NORM01",5), 
          rep("NORM02", 5), 
          rep("MOD02", 5), 
          rep("MOD03", 5),
          rep("NORM03", 5) )

genes=rep(c("FOXA1","AR","MYC","ENSG00000281133","FAM138A"), 6)

expression_counts=rnorm(30, 25, 4)

FOXA1=c("FOXA1", "protein_coding","ENSG00000129514.8")
AR=c("AR","protein_coding","ENSG00000169083.18")
MYC=c("MYC","protein_coding","ENSG00000136997.21")
ENSG00000281133=c("ENSG00000281133","pseudogene" ,"ENSG00000281133.1")
FAM138A=c("FAM138A", "lncRNA","ENSG00000237613.2")
df1=cbind.data.frame(samples,genes,expression_counts )

df2=rbind.data.frame(FOXA1, AR, MYC, ENSG00000281133, FAM138A)

colnames(df2)=c("gene_name", "gene_type", "gene_id")

df1=cbind.data.frame(df1, df2[match(df1$genes, df2$gene_name), c("gene_type", "gene_id")])

unique(df1$genes[which(df1$gene_type=="protein_coding")])
## [1] "FOXA1" "AR"    "MYC"
cases=unique(df1$samples[grep("MOD", df1$samples)])

controls=unique(df1$samples[grep("NORM", df1$samples)])

names(cases)=rep("case",3)

names(controls)=rep("control",3)

samples=c(cases, controls)

df1$annotation<-NA

df1$annotation=names(samples)[match(df1$samples, samples)]

df1
##     samples           genes expression_counts      gene_type            gene_id
## 1     MOD01           FOXA1          23.58046 protein_coding  ENSG00000129514.8
## 2     MOD01              AR          28.77553 protein_coding ENSG00000169083.18
## 3     MOD01             MYC          24.71959 protein_coding ENSG00000136997.21
## 4     MOD01 ENSG00000281133          22.62500     pseudogene  ENSG00000281133.1
## 5     MOD01         FAM138A          21.64108         lncRNA  ENSG00000237613.2
## 1.1  NORM01           FOXA1          22.12389 protein_coding  ENSG00000129514.8
## 2.1  NORM01              AR          25.29696 protein_coding ENSG00000169083.18
## 3.1  NORM01             MYC          25.98398 protein_coding ENSG00000136997.21
## 4.1  NORM01 ENSG00000281133          23.70522     pseudogene  ENSG00000281133.1
## 5.1  NORM01         FAM138A          21.00481         lncRNA  ENSG00000237613.2
## 1.2  NORM02           FOXA1          24.56363 protein_coding  ENSG00000129514.8
## 2.2  NORM02              AR          26.04510 protein_coding ENSG00000169083.18
## 3.2  NORM02             MYC          30.83418 protein_coding ENSG00000136997.21
## 4.2  NORM02 ENSG00000281133          23.57142     pseudogene  ENSG00000281133.1
## 5.2  NORM02         FAM138A          20.00303         lncRNA  ENSG00000237613.2
## 1.3   MOD02           FOXA1          25.23526 protein_coding  ENSG00000129514.8
## 2.3   MOD02              AR          29.66635 protein_coding ENSG00000169083.18
## 3.3   MOD02             MYC          28.14392 protein_coding ENSG00000136997.21
## 4.3   MOD02 ENSG00000281133          26.38283     pseudogene  ENSG00000281133.1
## 5.3   MOD02         FAM138A          19.50276         lncRNA  ENSG00000237613.2
## 1.4   MOD03           FOXA1          34.50365 protein_coding  ENSG00000129514.8
## 2.4   MOD03              AR          29.67558 protein_coding ENSG00000169083.18
## 3.4   MOD03             MYC          27.90093 protein_coding ENSG00000136997.21
## 4.4   MOD03 ENSG00000281133          22.27610     pseudogene  ENSG00000281133.1
## 5.4   MOD03         FAM138A          36.03155         lncRNA  ENSG00000237613.2
## 1.5  NORM03           FOXA1          22.78865 protein_coding  ENSG00000129514.8
## 2.5  NORM03              AR          27.10168 protein_coding ENSG00000169083.18
## 3.5  NORM03             MYC          26.59054 protein_coding ENSG00000136997.21
## 4.5  NORM03 ENSG00000281133          25.06675     pseudogene  ENSG00000281133.1
## 5.5  NORM03         FAM138A          21.61097         lncRNA  ENSG00000237613.2
##     annotation
## 1         case
## 2         case
## 3         case
## 4         case
## 5         case
## 1.1    control
## 2.1    control
## 3.1    control
## 4.1    control
## 5.1    control
## 1.2    control
## 2.2    control
## 3.2    control
## 4.2    control
## 5.2    control
## 1.3       case
## 2.3       case
## 3.3       case
## 4.3       case
## 5.3       case
## 1.4       case
## 2.4       case
## 3.4       case
## 4.4       case
## 5.4       case
## 1.5    control
## 2.5    control
## 3.5    control
## 4.5    control
## 5.5    control

  1. Create a function get_info that takes as input a number and a dataframe and return as output:
  • “LOW” if the number is lower than 10
  • “HIGH” if the number is greater than 40
  • the number of values in column expression_counts of df1 (previous exercise) that are lower than that number
get_info<-function(n,df){
  if(n<10){cat("LOW")
  }else if(n>40){cat("HIGH")
  }else {
        out=sum(df$expression_counts<n)
        return(out)}
}

get_info(8,df1)
## LOW
get_info(42,df1)
## HIGH
get_info(28,df1)
## [1] 23
  • create the vector gene_name = c("FOXA1","SRSF1","MYC","PTBP1","AR"). Then, use a for loop to iterate over the elements in the vector. For each element, print “Present” if it is found in the genes column of df1, or “Not Present” otherwise. (HINT: try to use "\n" to write each output in a new line)
  • use a for loop to iterate over the elements in the gene_name vector. If an element is not found in the genes column of df1, skip to the next element. Otherwise, select the rows corresponding to that gene and display the average of the expression_counts column.
  • create a variable total<-0. Use a for loop to iterate over the elements in the expression_counts column of df1. At each iteration, add the new value to total. The loop should terminate once total exceeds 150. Display the final value of total.
gene_name = c("FOXA1","SRSF1","MYC","PTBP1","AR")

for(gene in gene_name){
  if(gene %in% df1$genes){
    cat("Present \n")
  } else { cat("Not.Present \n")}
}
## Present 
## Not.Present 
## Present 
## Not.Present 
## Present
for(gene in gene_name){
  if(! gene %in% df1$genes){
    next
  } else { 
    m<-mean(subset(df1,genes==gene)$expression_counts)
    cat(m)
    cat("\n")}
}
## 25.46593
## 27.36219
## 27.7602
total<-0
for (counts in df1$expression_counts){
  if(total>150){break
  }else {
      total<-total+counts
    }
}
total
## [1] 168.7625
  1. Suppose you have the following list g:
    • Extract from the matrix in the list all rows that do not contain missing values
    • Sum by columns, by row and evaluate the mean by column and by row of the original matrix. Explore options in the functions you will use to exclude missing values and NaN (use the helper in R Studio).
    • Remove from the matrix in the list column 5 if it contains NA, NaN or infinite values.
    • Replace the matrix by removing the rows that contain missing values
    • Identify indexes of the vector in the list that contain infinite values
g=list(Value=c(NaN,32, NA,39, Inf, -Inf, 8.9, 4 ),
       Mat=matrix(c(1:9, NA, NaN, 989:103, Inf, NA, 10^7, 9^5, 6*7, 5/3, 6+2, 5-7), ncol=6, byrow = T),
       Df=cbind.data.frame(place=factor(c("Garden", "House", "Square", NA)), N=c(NA, 5, 7, NaN))
       
       )
# first solution (long)
g$Mat[!is.na(g$Mat[,1]) & !is.na(g$Mat[,2]) & !is.na(g$Mat[,3]) & !is.na(g$Mat[,4]) & !is.na(g$Mat[,5]) & !is.na(g$Mat[,6]),]
##            [,1]  [,2] [,3]       [,4] [,5] [,6]
##   [1,]        1     2    3   4.000000    5    6
##   [2,]      988   987  986 985.000000  984  983
##   [3,]      982   981  980 979.000000  978  977
##   [4,]      976   975  974 973.000000  972  971
##   [5,]      970   969  968 967.000000  966  965
##   [6,]      964   963  962 961.000000  960  959
##   [7,]      958   957  956 955.000000  954  953
##   [8,]      952   951  950 949.000000  948  947
##   [9,]      946   945  944 943.000000  942  941
##  [10,]      940   939  938 937.000000  936  935
##  [11,]      934   933  932 931.000000  930  929
##  [12,]      928   927  926 925.000000  924  923
##  [13,]      922   921  920 919.000000  918  917
##  [14,]      916   915  914 913.000000  912  911
##  [15,]      910   909  908 907.000000  906  905
##  [16,]      904   903  902 901.000000  900  899
##  [17,]      898   897  896 895.000000  894  893
##  [18,]      892   891  890 889.000000  888  887
##  [19,]      886   885  884 883.000000  882  881
##  [20,]      880   879  878 877.000000  876  875
##  [21,]      874   873  872 871.000000  870  869
##  [22,]      868   867  866 865.000000  864  863
##  [23,]      862   861  860 859.000000  858  857
##  [24,]      856   855  854 853.000000  852  851
##  [25,]      850   849  848 847.000000  846  845
##  [26,]      844   843  842 841.000000  840  839
##  [27,]      838   837  836 835.000000  834  833
##  [28,]      832   831  830 829.000000  828  827
##  [29,]      826   825  824 823.000000  822  821
##  [30,]      820   819  818 817.000000  816  815
##  [31,]      814   813  812 811.000000  810  809
##  [32,]      808   807  806 805.000000  804  803
##  [33,]      802   801  800 799.000000  798  797
##  [34,]      796   795  794 793.000000  792  791
##  [35,]      790   789  788 787.000000  786  785
##  [36,]      784   783  782 781.000000  780  779
##  [37,]      778   777  776 775.000000  774  773
##  [38,]      772   771  770 769.000000  768  767
##  [39,]      766   765  764 763.000000  762  761
##  [40,]      760   759  758 757.000000  756  755
##  [41,]      754   753  752 751.000000  750  749
##  [42,]      748   747  746 745.000000  744  743
##  [43,]      742   741  740 739.000000  738  737
##  [44,]      736   735  734 733.000000  732  731
##  [45,]      730   729  728 727.000000  726  725
##  [46,]      724   723  722 721.000000  720  719
##  [47,]      718   717  716 715.000000  714  713
##  [48,]      712   711  710 709.000000  708  707
##  [49,]      706   705  704 703.000000  702  701
##  [50,]      700   699  698 697.000000  696  695
##  [51,]      694   693  692 691.000000  690  689
##  [52,]      688   687  686 685.000000  684  683
##  [53,]      682   681  680 679.000000  678  677
##  [54,]      676   675  674 673.000000  672  671
##  [55,]      670   669  668 667.000000  666  665
##  [56,]      664   663  662 661.000000  660  659
##  [57,]      658   657  656 655.000000  654  653
##  [58,]      652   651  650 649.000000  648  647
##  [59,]      646   645  644 643.000000  642  641
##  [60,]      640   639  638 637.000000  636  635
##  [61,]      634   633  632 631.000000  630  629
##  [62,]      628   627  626 625.000000  624  623
##  [63,]      622   621  620 619.000000  618  617
##  [64,]      616   615  614 613.000000  612  611
##  [65,]      610   609  608 607.000000  606  605
##  [66,]      604   603  602 601.000000  600  599
##  [67,]      598   597  596 595.000000  594  593
##  [68,]      592   591  590 589.000000  588  587
##  [69,]      586   585  584 583.000000  582  581
##  [70,]      580   579  578 577.000000  576  575
##  [71,]      574   573  572 571.000000  570  569
##  [72,]      568   567  566 565.000000  564  563
##  [73,]      562   561  560 559.000000  558  557
##  [74,]      556   555  554 553.000000  552  551
##  [75,]      550   549  548 547.000000  546  545
##  [76,]      544   543  542 541.000000  540  539
##  [77,]      538   537  536 535.000000  534  533
##  [78,]      532   531  530 529.000000  528  527
##  [79,]      526   525  524 523.000000  522  521
##  [80,]      520   519  518 517.000000  516  515
##  [81,]      514   513  512 511.000000  510  509
##  [82,]      508   507  506 505.000000  504  503
##  [83,]      502   501  500 499.000000  498  497
##  [84,]      496   495  494 493.000000  492  491
##  [85,]      490   489  488 487.000000  486  485
##  [86,]      484   483  482 481.000000  480  479
##  [87,]      478   477  476 475.000000  474  473
##  [88,]      472   471  470 469.000000  468  467
##  [89,]      466   465  464 463.000000  462  461
##  [90,]      460   459  458 457.000000  456  455
##  [91,]      454   453  452 451.000000  450  449
##  [92,]      448   447  446 445.000000  444  443
##  [93,]      442   441  440 439.000000  438  437
##  [94,]      436   435  434 433.000000  432  431
##  [95,]      430   429  428 427.000000  426  425
##  [96,]      424   423  422 421.000000  420  419
##  [97,]      418   417  416 415.000000  414  413
##  [98,]      412   411  410 409.000000  408  407
##  [99,]      406   405  404 403.000000  402  401
## [100,]      400   399  398 397.000000  396  395
## [101,]      394   393  392 391.000000  390  389
## [102,]      388   387  386 385.000000  384  383
## [103,]      382   381  380 379.000000  378  377
## [104,]      376   375  374 373.000000  372  371
## [105,]      370   369  368 367.000000  366  365
## [106,]      364   363  362 361.000000  360  359
## [107,]      358   357  356 355.000000  354  353
## [108,]      352   351  350 349.000000  348  347
## [109,]      346   345  344 343.000000  342  341
## [110,]      340   339  338 337.000000  336  335
## [111,]      334   333  332 331.000000  330  329
## [112,]      328   327  326 325.000000  324  323
## [113,]      322   321  320 319.000000  318  317
## [114,]      316   315  314 313.000000  312  311
## [115,]      310   309  308 307.000000  306  305
## [116,]      304   303  302 301.000000  300  299
## [117,]      298   297  296 295.000000  294  293
## [118,]      292   291  290 289.000000  288  287
## [119,]      286   285  284 283.000000  282  281
## [120,]      280   279  278 277.000000  276  275
## [121,]      274   273  272 271.000000  270  269
## [122,]      268   267  266 265.000000  264  263
## [123,]      262   261  260 259.000000  258  257
## [124,]      256   255  254 253.000000  252  251
## [125,]      250   249  248 247.000000  246  245
## [126,]      244   243  242 241.000000  240  239
## [127,]      238   237  236 235.000000  234  233
## [128,]      232   231  230 229.000000  228  227
## [129,]      226   225  224 223.000000  222  221
## [130,]      220   219  218 217.000000  216  215
## [131,]      214   213  212 211.000000  210  209
## [132,]      208   207  206 205.000000  204  203
## [133,]      202   201  200 199.000000  198  197
## [134,]      196   195  194 193.000000  192  191
## [135,]      190   189  188 187.000000  186  185
## [136,]      184   183  182 181.000000  180  179
## [137,]      178   177  176 175.000000  174  173
## [138,]      172   171  170 169.000000  168  167
## [139,]      166   165  164 163.000000  162  161
## [140,]      160   159  158 157.000000  156  155
## [141,]      154   153  152 151.000000  150  149
## [142,]      148   147  146 145.000000  144  143
## [143,]      142   141  140 139.000000  138  137
## [144,]      136   135  134 133.000000  132  131
## [145,]      130   129  128 127.000000  126  125
## [146,]      124   123  122 121.000000  120  119
## [147,]      118   117  116 115.000000  114  113
## [148,]      112   111  110 109.000000  108  107
## [149,] 10000000 59049   42   1.666667    8   -2
# second solution (short)
g$Mat[rowSums(is.na(g$Mat))==0,]
##            [,1]  [,2] [,3]       [,4] [,5] [,6]
##   [1,]        1     2    3   4.000000    5    6
##   [2,]      988   987  986 985.000000  984  983
##   [3,]      982   981  980 979.000000  978  977
##   [4,]      976   975  974 973.000000  972  971
##   [5,]      970   969  968 967.000000  966  965
##   [6,]      964   963  962 961.000000  960  959
##   [7,]      958   957  956 955.000000  954  953
##   [8,]      952   951  950 949.000000  948  947
##   [9,]      946   945  944 943.000000  942  941
##  [10,]      940   939  938 937.000000  936  935
##  [11,]      934   933  932 931.000000  930  929
##  [12,]      928   927  926 925.000000  924  923
##  [13,]      922   921  920 919.000000  918  917
##  [14,]      916   915  914 913.000000  912  911
##  [15,]      910   909  908 907.000000  906  905
##  [16,]      904   903  902 901.000000  900  899
##  [17,]      898   897  896 895.000000  894  893
##  [18,]      892   891  890 889.000000  888  887
##  [19,]      886   885  884 883.000000  882  881
##  [20,]      880   879  878 877.000000  876  875
##  [21,]      874   873  872 871.000000  870  869
##  [22,]      868   867  866 865.000000  864  863
##  [23,]      862   861  860 859.000000  858  857
##  [24,]      856   855  854 853.000000  852  851
##  [25,]      850   849  848 847.000000  846  845
##  [26,]      844   843  842 841.000000  840  839
##  [27,]      838   837  836 835.000000  834  833
##  [28,]      832   831  830 829.000000  828  827
##  [29,]      826   825  824 823.000000  822  821
##  [30,]      820   819  818 817.000000  816  815
##  [31,]      814   813  812 811.000000  810  809
##  [32,]      808   807  806 805.000000  804  803
##  [33,]      802   801  800 799.000000  798  797
##  [34,]      796   795  794 793.000000  792  791
##  [35,]      790   789  788 787.000000  786  785
##  [36,]      784   783  782 781.000000  780  779
##  [37,]      778   777  776 775.000000  774  773
##  [38,]      772   771  770 769.000000  768  767
##  [39,]      766   765  764 763.000000  762  761
##  [40,]      760   759  758 757.000000  756  755
##  [41,]      754   753  752 751.000000  750  749
##  [42,]      748   747  746 745.000000  744  743
##  [43,]      742   741  740 739.000000  738  737
##  [44,]      736   735  734 733.000000  732  731
##  [45,]      730   729  728 727.000000  726  725
##  [46,]      724   723  722 721.000000  720  719
##  [47,]      718   717  716 715.000000  714  713
##  [48,]      712   711  710 709.000000  708  707
##  [49,]      706   705  704 703.000000  702  701
##  [50,]      700   699  698 697.000000  696  695
##  [51,]      694   693  692 691.000000  690  689
##  [52,]      688   687  686 685.000000  684  683
##  [53,]      682   681  680 679.000000  678  677
##  [54,]      676   675  674 673.000000  672  671
##  [55,]      670   669  668 667.000000  666  665
##  [56,]      664   663  662 661.000000  660  659
##  [57,]      658   657  656 655.000000  654  653
##  [58,]      652   651  650 649.000000  648  647
##  [59,]      646   645  644 643.000000  642  641
##  [60,]      640   639  638 637.000000  636  635
##  [61,]      634   633  632 631.000000  630  629
##  [62,]      628   627  626 625.000000  624  623
##  [63,]      622   621  620 619.000000  618  617
##  [64,]      616   615  614 613.000000  612  611
##  [65,]      610   609  608 607.000000  606  605
##  [66,]      604   603  602 601.000000  600  599
##  [67,]      598   597  596 595.000000  594  593
##  [68,]      592   591  590 589.000000  588  587
##  [69,]      586   585  584 583.000000  582  581
##  [70,]      580   579  578 577.000000  576  575
##  [71,]      574   573  572 571.000000  570  569
##  [72,]      568   567  566 565.000000  564  563
##  [73,]      562   561  560 559.000000  558  557
##  [74,]      556   555  554 553.000000  552  551
##  [75,]      550   549  548 547.000000  546  545
##  [76,]      544   543  542 541.000000  540  539
##  [77,]      538   537  536 535.000000  534  533
##  [78,]      532   531  530 529.000000  528  527
##  [79,]      526   525  524 523.000000  522  521
##  [80,]      520   519  518 517.000000  516  515
##  [81,]      514   513  512 511.000000  510  509
##  [82,]      508   507  506 505.000000  504  503
##  [83,]      502   501  500 499.000000  498  497
##  [84,]      496   495  494 493.000000  492  491
##  [85,]      490   489  488 487.000000  486  485
##  [86,]      484   483  482 481.000000  480  479
##  [87,]      478   477  476 475.000000  474  473
##  [88,]      472   471  470 469.000000  468  467
##  [89,]      466   465  464 463.000000  462  461
##  [90,]      460   459  458 457.000000  456  455
##  [91,]      454   453  452 451.000000  450  449
##  [92,]      448   447  446 445.000000  444  443
##  [93,]      442   441  440 439.000000  438  437
##  [94,]      436   435  434 433.000000  432  431
##  [95,]      430   429  428 427.000000  426  425
##  [96,]      424   423  422 421.000000  420  419
##  [97,]      418   417  416 415.000000  414  413
##  [98,]      412   411  410 409.000000  408  407
##  [99,]      406   405  404 403.000000  402  401
## [100,]      400   399  398 397.000000  396  395
## [101,]      394   393  392 391.000000  390  389
## [102,]      388   387  386 385.000000  384  383
## [103,]      382   381  380 379.000000  378  377
## [104,]      376   375  374 373.000000  372  371
## [105,]      370   369  368 367.000000  366  365
## [106,]      364   363  362 361.000000  360  359
## [107,]      358   357  356 355.000000  354  353
## [108,]      352   351  350 349.000000  348  347
## [109,]      346   345  344 343.000000  342  341
## [110,]      340   339  338 337.000000  336  335
## [111,]      334   333  332 331.000000  330  329
## [112,]      328   327  326 325.000000  324  323
## [113,]      322   321  320 319.000000  318  317
## [114,]      316   315  314 313.000000  312  311
## [115,]      310   309  308 307.000000  306  305
## [116,]      304   303  302 301.000000  300  299
## [117,]      298   297  296 295.000000  294  293
## [118,]      292   291  290 289.000000  288  287
## [119,]      286   285  284 283.000000  282  281
## [120,]      280   279  278 277.000000  276  275
## [121,]      274   273  272 271.000000  270  269
## [122,]      268   267  266 265.000000  264  263
## [123,]      262   261  260 259.000000  258  257
## [124,]      256   255  254 253.000000  252  251
## [125,]      250   249  248 247.000000  246  245
## [126,]      244   243  242 241.000000  240  239
## [127,]      238   237  236 235.000000  234  233
## [128,]      232   231  230 229.000000  228  227
## [129,]      226   225  224 223.000000  222  221
## [130,]      220   219  218 217.000000  216  215
## [131,]      214   213  212 211.000000  210  209
## [132,]      208   207  206 205.000000  204  203
## [133,]      202   201  200 199.000000  198  197
## [134,]      196   195  194 193.000000  192  191
## [135,]      190   189  188 187.000000  186  185
## [136,]      184   183  182 181.000000  180  179
## [137,]      178   177  176 175.000000  174  173
## [138,]      172   171  170 169.000000  168  167
## [139,]      166   165  164 163.000000  162  161
## [140,]      160   159  158 157.000000  156  155
## [141,]      154   153  152 151.000000  150  149
## [142,]      148   147  146 145.000000  144  143
## [143,]      142   141  140 139.000000  138  137
## [144,]      136   135  134 133.000000  132  131
## [145,]      130   129  128 127.000000  126  125
## [146,]      124   123  122 121.000000  120  119
## [147,]      118   117  116 115.000000  114  113
## [148,]      112   111  110 109.000000  108  107
## [149,] 10000000 59049   42   1.666667    8   -2
colSums(g$Mat, na.rm=T) # Notice that in this case not only NA are removed, but also NaN
## [1] 10080964.00   139867.00    80714.00    80517.67         Inf    81108.00
rowSums(g$Mat, na.rm=T)
##   [1]       21     1013     5913     5877     5841     5805     5769     5733
##   [9]     5697     5661     5625     5589     5553     5517     5481     5445
##  [17]     5409     5373     5337     5301     5265     5229     5193     5157
##  [25]     5121     5085     5049     5013     4977     4941     4905     4869
##  [33]     4833     4797     4761     4725     4689     4653     4617     4581
##  [41]     4545     4509     4473     4437     4401     4365     4329     4293
##  [49]     4257     4221     4185     4149     4113     4077     4041     4005
##  [57]     3969     3933     3897     3861     3825     3789     3753     3717
##  [65]     3681     3645     3609     3573     3537     3501     3465     3429
##  [73]     3393     3357     3321     3285     3249     3213     3177     3141
##  [81]     3105     3069     3033     2997     2961     2925     2889     2853
##  [89]     2817     2781     2745     2709     2673     2637     2601     2565
##  [97]     2529     2493     2457     2421     2385     2349     2313     2277
## [105]     2241     2205     2169     2133     2097     2061     2025     1989
## [113]     1953     1917     1881     1845     1809     1773     1737     1701
## [121]     1665     1629     1593     1557     1521     1485     1449     1413
## [129]     1377     1341     1305     1269     1233     1197     1161     1125
## [137]     1089     1053     1017      981      945      909      873      837
## [145]      801      765      729      693      657      Inf 10059099
colMeans(g$Mat, na.rm=T)
## [1] 66761.3510   926.2715   534.5298   536.7844        Inf   540.7200
rowMeans(g$Mat, na.rm=T) 
##   [1]       3.50     253.25     985.50     979.50     973.50     967.50
##   [7]     961.50     955.50     949.50     943.50     937.50     931.50
##  [13]     925.50     919.50     913.50     907.50     901.50     895.50
##  [19]     889.50     883.50     877.50     871.50     865.50     859.50
##  [25]     853.50     847.50     841.50     835.50     829.50     823.50
##  [31]     817.50     811.50     805.50     799.50     793.50     787.50
##  [37]     781.50     775.50     769.50     763.50     757.50     751.50
##  [43]     745.50     739.50     733.50     727.50     721.50     715.50
##  [49]     709.50     703.50     697.50     691.50     685.50     679.50
##  [55]     673.50     667.50     661.50     655.50     649.50     643.50
##  [61]     637.50     631.50     625.50     619.50     613.50     607.50
##  [67]     601.50     595.50     589.50     583.50     577.50     571.50
##  [73]     565.50     559.50     553.50     547.50     541.50     535.50
##  [79]     529.50     523.50     517.50     511.50     505.50     499.50
##  [85]     493.50     487.50     481.50     475.50     469.50     463.50
##  [91]     457.50     451.50     445.50     439.50     433.50     427.50
##  [97]     421.50     415.50     409.50     403.50     397.50     391.50
## [103]     385.50     379.50     373.50     367.50     361.50     355.50
## [109]     349.50     343.50     337.50     331.50     325.50     319.50
## [115]     313.50     307.50     301.50     295.50     289.50     283.50
## [121]     277.50     271.50     265.50     259.50     253.50     247.50
## [127]     241.50     235.50     229.50     223.50     217.50     211.50
## [133]     205.50     199.50     193.50     187.50     181.50     175.50
## [139]     169.50     163.50     157.50     151.50     145.50     139.50
## [145]     133.50     127.50     121.50     115.50     109.50        Inf
## [151] 1676516.44
sum(unique(is.na(g$Mat[,5]) | is.nan(g$Mat[,5]) | is.infinite(g$Mat[,5]))) # There is at least 1 row in which one of theese conditions happens, so I remove the column
## [1] 1
g$Mat=g$Mat[,-5]

g$Mat
##            [,1]  [,2] [,3]       [,4] [,5]
##   [1,]        1     2    3   4.000000    6
##   [2,]        7     8    9         NA  989
##   [3,]      988   987  986 985.000000  983
##   [4,]      982   981  980 979.000000  977
##   [5,]      976   975  974 973.000000  971
##   [6,]      970   969  968 967.000000  965
##   [7,]      964   963  962 961.000000  959
##   [8,]      958   957  956 955.000000  953
##   [9,]      952   951  950 949.000000  947
##  [10,]      946   945  944 943.000000  941
##  [11,]      940   939  938 937.000000  935
##  [12,]      934   933  932 931.000000  929
##  [13,]      928   927  926 925.000000  923
##  [14,]      922   921  920 919.000000  917
##  [15,]      916   915  914 913.000000  911
##  [16,]      910   909  908 907.000000  905
##  [17,]      904   903  902 901.000000  899
##  [18,]      898   897  896 895.000000  893
##  [19,]      892   891  890 889.000000  887
##  [20,]      886   885  884 883.000000  881
##  [21,]      880   879  878 877.000000  875
##  [22,]      874   873  872 871.000000  869
##  [23,]      868   867  866 865.000000  863
##  [24,]      862   861  860 859.000000  857
##  [25,]      856   855  854 853.000000  851
##  [26,]      850   849  848 847.000000  845
##  [27,]      844   843  842 841.000000  839
##  [28,]      838   837  836 835.000000  833
##  [29,]      832   831  830 829.000000  827
##  [30,]      826   825  824 823.000000  821
##  [31,]      820   819  818 817.000000  815
##  [32,]      814   813  812 811.000000  809
##  [33,]      808   807  806 805.000000  803
##  [34,]      802   801  800 799.000000  797
##  [35,]      796   795  794 793.000000  791
##  [36,]      790   789  788 787.000000  785
##  [37,]      784   783  782 781.000000  779
##  [38,]      778   777  776 775.000000  773
##  [39,]      772   771  770 769.000000  767
##  [40,]      766   765  764 763.000000  761
##  [41,]      760   759  758 757.000000  755
##  [42,]      754   753  752 751.000000  749
##  [43,]      748   747  746 745.000000  743
##  [44,]      742   741  740 739.000000  737
##  [45,]      736   735  734 733.000000  731
##  [46,]      730   729  728 727.000000  725
##  [47,]      724   723  722 721.000000  719
##  [48,]      718   717  716 715.000000  713
##  [49,]      712   711  710 709.000000  707
##  [50,]      706   705  704 703.000000  701
##  [51,]      700   699  698 697.000000  695
##  [52,]      694   693  692 691.000000  689
##  [53,]      688   687  686 685.000000  683
##  [54,]      682   681  680 679.000000  677
##  [55,]      676   675  674 673.000000  671
##  [56,]      670   669  668 667.000000  665
##  [57,]      664   663  662 661.000000  659
##  [58,]      658   657  656 655.000000  653
##  [59,]      652   651  650 649.000000  647
##  [60,]      646   645  644 643.000000  641
##  [61,]      640   639  638 637.000000  635
##  [62,]      634   633  632 631.000000  629
##  [63,]      628   627  626 625.000000  623
##  [64,]      622   621  620 619.000000  617
##  [65,]      616   615  614 613.000000  611
##  [66,]      610   609  608 607.000000  605
##  [67,]      604   603  602 601.000000  599
##  [68,]      598   597  596 595.000000  593
##  [69,]      592   591  590 589.000000  587
##  [70,]      586   585  584 583.000000  581
##  [71,]      580   579  578 577.000000  575
##  [72,]      574   573  572 571.000000  569
##  [73,]      568   567  566 565.000000  563
##  [74,]      562   561  560 559.000000  557
##  [75,]      556   555  554 553.000000  551
##  [76,]      550   549  548 547.000000  545
##  [77,]      544   543  542 541.000000  539
##  [78,]      538   537  536 535.000000  533
##  [79,]      532   531  530 529.000000  527
##  [80,]      526   525  524 523.000000  521
##  [81,]      520   519  518 517.000000  515
##  [82,]      514   513  512 511.000000  509
##  [83,]      508   507  506 505.000000  503
##  [84,]      502   501  500 499.000000  497
##  [85,]      496   495  494 493.000000  491
##  [86,]      490   489  488 487.000000  485
##  [87,]      484   483  482 481.000000  479
##  [88,]      478   477  476 475.000000  473
##  [89,]      472   471  470 469.000000  467
##  [90,]      466   465  464 463.000000  461
##  [91,]      460   459  458 457.000000  455
##  [92,]      454   453  452 451.000000  449
##  [93,]      448   447  446 445.000000  443
##  [94,]      442   441  440 439.000000  437
##  [95,]      436   435  434 433.000000  431
##  [96,]      430   429  428 427.000000  425
##  [97,]      424   423  422 421.000000  419
##  [98,]      418   417  416 415.000000  413
##  [99,]      412   411  410 409.000000  407
## [100,]      406   405  404 403.000000  401
## [101,]      400   399  398 397.000000  395
## [102,]      394   393  392 391.000000  389
## [103,]      388   387  386 385.000000  383
## [104,]      382   381  380 379.000000  377
## [105,]      376   375  374 373.000000  371
## [106,]      370   369  368 367.000000  365
## [107,]      364   363  362 361.000000  359
## [108,]      358   357  356 355.000000  353
## [109,]      352   351  350 349.000000  347
## [110,]      346   345  344 343.000000  341
## [111,]      340   339  338 337.000000  335
## [112,]      334   333  332 331.000000  329
## [113,]      328   327  326 325.000000  323
## [114,]      322   321  320 319.000000  317
## [115,]      316   315  314 313.000000  311
## [116,]      310   309  308 307.000000  305
## [117,]      304   303  302 301.000000  299
## [118,]      298   297  296 295.000000  293
## [119,]      292   291  290 289.000000  287
## [120,]      286   285  284 283.000000  281
## [121,]      280   279  278 277.000000  275
## [122,]      274   273  272 271.000000  269
## [123,]      268   267  266 265.000000  263
## [124,]      262   261  260 259.000000  257
## [125,]      256   255  254 253.000000  251
## [126,]      250   249  248 247.000000  245
## [127,]      244   243  242 241.000000  239
## [128,]      238   237  236 235.000000  233
## [129,]      232   231  230 229.000000  227
## [130,]      226   225  224 223.000000  221
## [131,]      220   219  218 217.000000  215
## [132,]      214   213  212 211.000000  209
## [133,]      208   207  206 205.000000  203
## [134,]      202   201  200 199.000000  197
## [135,]      196   195  194 193.000000  191
## [136,]      190   189  188 187.000000  185
## [137,]      184   183  182 181.000000  179
## [138,]      178   177  176 175.000000  173
## [139,]      172   171  170 169.000000  167
## [140,]      166   165  164 163.000000  161
## [141,]      160   159  158 157.000000  155
## [142,]      154   153  152 151.000000  149
## [143,]      148   147  146 145.000000  143
## [144,]      142   141  140 139.000000  137
## [145,]      136   135  134 133.000000  131
## [146,]      130   129  128 127.000000  125
## [147,]      124   123  122 121.000000  119
## [148,]      118   117  116 115.000000  113
## [149,]      112   111  110 109.000000  107
## [150,]      106   105  104 103.000000   NA
## [151,] 10000000 59049   42   1.666667   -2
g$Df=subset(g$Df, !is.na(place) & !is.na(N))

g$Df
##    place N
## 2  House 5
## 3 Square 7
which(is.infinite(g$Value))
## [1] 5 6