I'm new to R. I'm extracting important columns from single table using following code: File2<-"file.txt" table2<- read.delim(File2, skip=19, sep=";", header=F, na.strings=NA, fill=T) #extracting column 7 where rows match "ID" col1<- table2[grep("ID", table2[,1]),7] #similarly extracting column 9,11,13,15 col2<- table2[grep("ID", table2[,1]),9] col3<- table2[grep("ID", table2[,1]),11] col4<- table2[grep("ID", table2[,1]),13] col5<- table2[grep("ID", table2[,1]),15] there are also some other single columns I extracted from other file. Now I want to combine all these single columns into a single table with corresponding headers. Any hint on how that can be done? Thanks. i.e file3.txt col1 col2 col3 col4 col5 Regards, Anand Now how can I combine -- View this message in context: http://r.789695.n4.nabble.com/Adding-rows-to-column-tp3005607p3005607.html Sent from the R help mailing list archive at Nabble.com.
Hi! Would df<- table2[grep("ID",table2[,1]), c(7,9,11,13,15)] do what you expect? Ivan Le 10/21/2010 15:42, amb1networks a ?crit :> I'm new to R. > I'm extracting important columns from single table using following code: > > File2<-"file.txt" > table2<- read.delim(File2, skip=19, sep=";", header=F, na.strings=NA, > fill=T) > #extracting column 7 where rows match "ID" > col1<- table2[grep("ID", table2[,1]),7] > #similarly extracting column 9,11,13,15 > col2<- table2[grep("ID", table2[,1]),9] > col3<- table2[grep("ID", table2[,1]),11] > col4<- table2[grep("ID", table2[,1]),13] > col5<- table2[grep("ID", table2[,1]),15] > > there are also some other single columns I extracted from other file. Now I > want to combine all these single columns into a single table with > corresponding headers. Any hint on how that can be done? Thanks. > > i.e file3.txt > col1 col2 col3 col4 col5 > > Regards, > > Anand > > > > Now how can I combine >-- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php
If I understand correctly you want to create a new dataframe with selected columns which can be achieved this was as well, it will right away create a new dataframe with column headers df2<-df1[ ,c(3,7,9,11,13,15)] -- View this message in context: http://r.789695.n4.nabble.com/Adding-rows-to-column-tp3005607p3006284.html Sent from the R help mailing list archive at Nabble.com.