Need an explanation for a particular R code snippet

68 views Asked by At

The following is the code for which i need an explanation for:

for (i in id) {
data <- read.csv(files[i] )

c <- complete.cases(data)
naRm <- data[c, ]
completeCases <- rbind(completeCases, c(i, nrow(naRm)))

as i understand, the variable c here stores multiple logical values. The line after, that seems foreign to me. How does data[c, ] work? FYI, I am an R newbie.

1

There are 1 answers

0
cr1msonB1ade On

complete.classes looks for all rows that are "complete", have no missing values. Here is the man page. Thus the completeCases object will tell you the number of "complete" rows in each file you have just read. You really don't need to store the value of i in the rbind call though as it is just the row number, so it is redundant. A vector would do just fine for this application.

Also looks like you are missing a close brackets or this isn't a complete chunk of code.