[R] subsetting a dataframe
spencer.graves at pdf.com
Mon Apr 7 22:38:44 CEST 2003
> df <- data.frame(a=1, b=2, c=3)
> df1 <- data.frame(a=1, b=2, c=3)
> df1[,!is.element(names(df1), "b")]
1 1 3
Chris Handorf wrote:
> How does one remove a column from a data frame when the name of
> the column to remove is stored in a variable?
> For Example:
> colname <- "LOT"
> newdf <- subset(olddf,select = - colname)
> The above statement will give an error, but thats what I'm trying to
> If I had used:
> newdf <- subset(olddf,select = - LOT)
> then it would have worked, but as I said the column name is stored in a
> so I can't just enter it explicity.
> R-help at stat.math.ethz.ch mailing list
More information about the R-help