[R] Compiled name to object

Claus Atzenbeck claus.atzenbeck at freenet.de
Fri Nov 18 11:01:03 CET 2005


I have a tricky problem with composing a name that should represent an

I want to pass a data frame and a string that contains a column name to
a function, e.g.:

    check(testFrame, "seconds")

The function should now divide the testFrame into two subsets and call a
t-test on the numbers that are in the given column:

    check <- function(frame, column) {
      sessionNo <- c("s01", "s02", "s03", "s04", "s05", "s06")
      earlySessions <- subset(frame, frame$session %in% sessionNo)
      lateSessions <- subset(frame, !frame$session %in% sessionNo)
      t.test(earlySessions$column, lateSessions$column)

How can I get R to change "earlySessions$column" to whatever was passed
as string, in the above example "earlySessions$seconds"?

Thanks for any hint.

More information about the R-help mailing list