hello , I am new user in R . I have datafile (class = data.frame) which has 825 columns with unique column name i want extract 200 selected column from datafile how can I do this? my datafile look like.. Mi RBN RBF nDB nX 3 2.6225979 0.53132756 -0.80599902 -1.4471864 -0.5705269 10 0.4818746 -1.72143092 -2.19579027 2.0118824 -0.5705269 12 2.8519611 1.88298265 0.09614617 0.6282549 -0.5705269 20 0.6347834 -0.36977583 0.63255683 1.3200687 -0.5705269 I want to extract data with unique name of column , by "Mi","RBF" etc . I have stored character vector of desired column names. eg aa c("Mi","RBF",..) -- View this message in context: http://r.789695.n4.nabble.com/help-extract-data-using-column-names-tp4647869.html Sent from the R help mailing list archive at Nabble.com.
Is this what you want:> x <- read.table(text = " Mi RBN RBF nDB nX+ 3 2.6225979 0.53132756 -0.80599902 -1.4471864 -0.5705269 + 10 0.4818746 -1.72143092 -2.19579027 2.0118824 -0.5705269 + 12 2.8519611 1.88298265 0.09614617 0.6282549 -0.5705269 + 20 0.6347834 -0.36977583 0.63255683 1.3200687 -0.5705269", header = TRUE)> > extract <- c("Mi", "nX") > x[, extract]Mi nX 3 2.6225979 -0.5705269 10 0.4818746 -0.5705269 12 2.8519611 -0.5705269 20 0.6347834 -0.5705269 On Tue, Oct 30, 2012 at 10:09 AM, alex_123 <deepak.juit at gmail.com> wrote:> hello , I am new user in R . I have datafile (class = data.frame) which has > 825 columns with unique column name i want extract 200 selected column from > datafile how can I do this? > my datafile look like.. > Mi RBN RBF nDB nX > 3 2.6225979 0.53132756 -0.80599902 -1.4471864 -0.5705269 > 10 0.4818746 -1.72143092 -2.19579027 2.0118824 -0.5705269 > 12 2.8519611 1.88298265 0.09614617 0.6282549 -0.5705269 > 20 0.6347834 -0.36977583 0.63255683 1.3200687 -0.5705269 > > > I want to extract data with unique name of column , by "Mi","RBF" etc . I > have stored character vector of desired column names. eg aa > c("Mi","RBF",..) > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/help-extract-data-using-column-names-tp4647869.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
A look at the tutorial might help here, but anyway: Say you have that dataframe down there with the name myData (you should use dput() to give us the data btw), then you can subset that by using myData[rows,columns], where left of the comma you define which rows you want, and right of the comma is which columns you want. If you leave it blank, all will be selected. So you want all rows from the columns, which names are in aa, then you would write myData[ , aa] On 30.10.2012, at 15:09, alex_123 wrote:> hello , I am new user in R . I have datafile (class = data.frame) which has > 825 columns with unique column name i want extract 200 selected column from > datafile how can I do this? > my datafile look like.. > Mi RBN RBF nDB nX > 3 2.6225979 0.53132756 -0.80599902 -1.4471864 -0.5705269 > 10 0.4818746 -1.72143092 -2.19579027 2.0118824 -0.5705269 > 12 2.8519611 1.88298265 0.09614617 0.6282549 -0.5705269 > 20 0.6347834 -0.36977583 0.63255683 1.3200687 -0.5705269 > > > I want to extract data with unique name of column , by "Mi","RBF" etc . I > have stored character vector of desired column names. eg aa > c("Mi","RBF",..) > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/help-extract-data-using-column-names-tp4647869.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
Please read the Introduction to R tutorial that ships with R to get started with R. Quoting Rolf Turner: " Learn something about R; don't just hammer and hope. Read the introductory manuals and scan the FAQ." Cheers, Bert On Tue, Oct 30, 2012 at 7:09 AM, alex_123 <deepak.juit at gmail.com> wrote:> hello , I am new user in R . I have datafile (class = data.frame) which has > 825 columns with unique column name i want extract 200 selected column from > datafile how can I do this? > my datafile look like.. > Mi RBN RBF nDB nX > 3 2.6225979 0.53132756 -0.80599902 -1.4471864 -0.5705269 > 10 0.4818746 -1.72143092 -2.19579027 2.0118824 -0.5705269 > 12 2.8519611 1.88298265 0.09614617 0.6282549 -0.5705269 > 20 0.6347834 -0.36977583 0.63255683 1.3200687 -0.5705269 > > > I want to extract data with unique name of column , by "Mi","RBF" etc . I > have stored character vector of desired column names. eg aa > c("Mi","RBF",..) > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/help-extract-data-using-column-names-tp4647869.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm