[R] Parameter of a function used after $ in a data frame

William Dunlap wdunlap at tibco.com
Wed Aug 13 18:36:21 CEST 2014


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.



More information about the R-help mailing list