Re: [R] question: how to select a column from a dataframe in a function

2012-01-17 Thread Petr PIKAL
Hi > > Hi, > > I am creating a function and ran into the problem of selecting a column > from a dataset. It seems as though the $ function (as in data$columnname) > does not apply in the function. In simplified version: > > This works: > testf2<-function(data,columnnumber){print(data[,columnn

Re: [R] question: how to select a column from a dataframe in a function

2012-01-13 Thread R. Michael Weylandt
Just put the columnname variable into the brackets as well: they accept strings. As a general rule, always use the brackets (single or double) when programming: `$` has some great features for interactive use but can bite if you're not careful. Michael On Fri, Jan 13, 2012 at 5:34 PM, Julia Burg

[R] question: how to select a column from a dataframe in a function

2012-01-13 Thread Julia Burggraaf
Hi, I am creating a function and ran into the problem of selecting a column from a dataset. It seems as though the $ function (as in data$columnname) does not apply in the function. In simplified version: This works: testf2<-function(data,columnnumber){print(data[,columnnumber])} But this doesn