Dear Claus
You can write
earlySessions[,"seconds"] instead of earlySessions$seconds and
with that syntax you can also use:
col1 <- "seconds"
earlySessions[,col1]
and you will get what you are looking for.
Best regards,
Christoph Buser
--------------------------------------------------------------
Christoph Buser <buser at stat.math.ethz.ch>
Seminar fuer Statistik, LEO C13
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-44-632-4673 fax: 632-1228
http://stat.ethz.ch/~buser/
--------------------------------------------------------------
Claus Atzenbeck writes:
> Hi,
>
> I have a tricky problem with composing a name that should represent an
> object:
>
> 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.
> Claus
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html