Re: [R] Simple question regarding name of column headers
Hi Addi, On Fri, Jul 16, 2010 at 3:22 PM, Addi Wei addi...@gmail.com wrote: names(miceTrainSample) [1] b_double KierA2 KierFlex Q_VSA_POS pID50 In the above code, how do I delete pID50 column to store the resulting object without indicating column 5. The code below does the trick, but I wish to delete the column by specifying -pID50 instead of 5. names(miceTrainSample)[-5] [1] b_double KierA2 KierFlex Q_VSA_POS If I understand you correctly, than this code will not do the trick. All it does is print the column names minus pID50. It does nothing to miceTrainSample. Anyway, I have often wished that something like new.mt.sample - miceTrainSample[, -pID50] would return miceTrainSample without the pID50 column. Here are three alternative ways to do it. # Method 1: Assign NULL to the column new.mt.sample - miceTrainsSample new.mt.sample$pID50 - NULL # Method 2: Use which() new.mt.sample - miceTrainSample[, - which(names(miceTrainSample == pID50)] # Method 3: use %in% (the one I usually use) new.mt.sample - miceTrainSample[, ! names(miceTrainSample) %in% pID50] Hope it helps, Ista -- View this message in context: http://r.789695.n4.nabble.com/Simple-question-regarding-name-of-column-headers-tp2291534p2291534.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ 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.
Re: [R] Simple question regarding name of column headers
Anyway, I have often wished that something like new.mt.sample - miceTrainSample[, -pID50] would return miceTrainSample without the pID50 column. Here are three alternative ways to do it. # Method 1: Assign NULL to the column new.mt.sample - miceTrainsSample new.mt.sample$pID50 - NULL # Method 2: Use which() new.mt.sample - miceTrainSample[, - which(names(miceTrainSample == pID50)] # Method 3: use %in% (the one I usually use) new.mt.sample - miceTrainSample[, ! names(miceTrainSample) %in% pID50] As a variation on Method 1... df - data.frame(a = 1:10, b = 2:11, c = 3:12) transform(df, a = NULL) __ 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.
Re: [R] Simple question regarding name of column headers
subset(miceTrainSample, select = -plD50) On Fri, Jul 16, 2010 at 11:22 AM, Addi Wei addi...@gmail.com wrote: names(miceTrainSample) [1] b_double KierA2 KierFlex Q_VSA_POS pID50 In the above code, how do I delete pID50 column to store the resulting object without indicating column 5. The code below does the trick, but I wish to delete the column by specifying -pID50 instead of 5. names(miceTrainSample)[-5] [1] b_double KierA2 KierFlex Q_VSA_POS -- View this message in context: http://r.789695.n4.nabble.com/Simple-question-regarding-name-of-column-headers-tp2291534p2291534.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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.