madhvi.gupta
2014-Aug-13 11:33 UTC
[R] Parameter of a function used after $ in a data frame
Hi, Can anyone please tell me how to use a argument of a function after $ sign of a data frame.That argument is one of the column name of the data frame. Thanks, Madhvi
Rui Barradas
2014-Aug-13 16:25 UTC
[R] Parameter of a function used after $ in a data frame
I don't believe I understand your question, but here it goes. dat <- data.frame(x = rnorm(100), y = runif(100)) mean(dat$x) Hope this helps, Rui Barradas Em 13-08-2014 12:33, madhvi.gupta escreveu:> Hi, > Can anyone please tell me how to use a argument of a function after $ > sign of a data frame.That argument is one of the column name of the data > frame. > > Thanks, > Madhvi > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
William Dunlap
2014-Aug-13 16:36 UTC
[R] Parameter of a function used after $ in a data frame
Use [[ instead of $. E.g., f <- function(columnName) { d <- data.frame(x=1, y=2, z=3) d[[columnName]] } f("z") # 3 cName <- "y" f(cName) # 2 Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Aug 13, 2014 at 4:33 AM, madhvi.gupta <madhvi.gupta at orkash.com> wrote:> Hi, > Can anyone please tell me how to use a argument of a function after $ sign > of a data frame.That argument is one of the column name of the data frame. > > Thanks, > Madhvi > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.