[R] dropping variables from a data frame inside a function
David Winsemius
dwinsemius at comcast.net
Fri Jun 22 23:19:17 CEST 2012
On Jun 22, 2012, at 5:09 PM, Joseph Boyer wrote:
> Why doesn't this work?
>
> #Drop a variable name from a data frame
>
> DropLikeSAS <- function(x,df) {
>
> df[[x]] <- NULL
>
> 0
>
> }
>
> DropLikeSAS("VarName", DataFrameName)
>
>
> Try it. The column VarName will not be deleted from the data frame
> DataFrameName.
>
>
> But
>
> x <- "VarName"
> DataFrameName[[x]] <- NULL
>
> Works.
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list