My preferred solution would be to use the select option of the subset function.
> data ( iris ) > names ( iris ) [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species" # KEEP-like way > iris_subset_by_keep <- subset ( iris, select = c( "Sepal.Length", "Species" ) > ) # DROP-like way > iris_subset_by_drop <- subset ( iris, select = c ( -Sepal.Width, > -Petal.Length, -Petal.Width) ) > identical ( iris_subset_by_keep , iris_subset_by_drop ) [1] TRUE > names ( iris_subset_by_keep ) [1] "Sepal.Length" "Species" > p.s. data NeweRa ( drop = SAS ); set Much_Better; eRic ----- Original message ----- From: "Wensui Liu" <liuwen...@gmail.com> To: sarjin...@yahoo.com Cc: r-help@r-project.org Date: Sat, 19 Dec 2009 20:19:51 -0500 Subject: Re: [R] DROP and KEEP statements in R drop example. > data(iris) > summary(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300 Median :5.800 Median :3.000 Median :4.350 Median :1.300 Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800 Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500 Species setosa :50 versicolor:50 virginica :50 > iris$Species <- NULL > summary(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300 Median :5.800 Median :3.000 Median :4.350 Median :1.300 Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800 Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500 On Sat, Dec 19, 2009 at 3:21 PM, <sarjin...@yahoo.com> wrote: > What is equivalent to DROP or KEEP statements of SAS in R? > > -- > This message was sent on behalf of sarjin...@yahoo.com at > openSubscriber.com > http://www.opensubscriber.com/messages/r-help@r-project.org/topic.html > > ______________________________________________ > R-help@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. > -- ============================== WenSui Liu Blog : statcompute.spaces.live.com Tough Times Never Last. But Tough People Do. - Robert Schuller ============================== [[alternative HTML version deleted]] ______________________________________________ R-help@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. ______________________________________________ R-help@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.