0

I'm trying to filter through a list of 100 lists with four columns of data to pull out individual columns and operate on them.

The columns are: Date/Time, Measurement 1, Measurement 2, Identity Variable

 filepull <- list of 100 lists    
column_name <- "foo"    
meanoflist <- NULL    
        for (i in 1:100) {
                      holder_variable<-filepull[[i]]
                      meanoflist[i]<-mean(na.omit(holder_variable$column_name))

                 }

holder_variable$"foo" gives me what I need, but holder_variable$column_name gives me NULL. What gives?

Thx for the help!

GarlicKnot
  • 94
  • 3

1 Answers1

1

When you use the $ operator, the input doesn't get evaluated; it will be used as-is. So, by using holder_variable$column_name, you are actually trying to get the column with the name column_name. If you want to get the value with the name stored in a variable, use holder_variable[, column_name] (assuming holder_variable is a data.frame, from instance).

Take a look at this example, to better understand the difference.

codingEnthusiast
  • 3,800
  • 2
  • 25
  • 37