hi, If I have a table of data, from read.table or scan how can I extract various columns to create a matrix? And once I have the matrix, how can I add and remove columns? Thanks, j. -- ...................... ..... Jason C. Leach .. Current PGP/GPG Key ID: 43AD2024 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
I am sure this is in the R help/manuals somewhere. Suppose your matrix, data is of dim 10 by 5 and you want to extract the the columns 1,2,4. Then you use newdata <- data[ , c(1,2,4). Now you changed your mind and want to get rid of column 1, then you use newdata2 <- data[ , -1]. If you had used newdata instead of newdata2, then you newdata will be overwritten instead. For rows you use data[ j , ] where j are the number(s) of rows you want to extract. And use - j for the subset of rows you want to get rid off. I would suggest you have a look at the manual again. ----- Original Message ----- From: "Jason C. Leach" <jleach at mail.ocis.net> To: <r-help at stat.math.ethz.ch> Sent: Thursday, July 25, 2002 11:22 PM Subject: [R] Manipulating Matricies> hi, > > If I have a table of data, from read.table or scan how can I > extract various columns to create a matrix? And once I have the > matrix, how can I add and remove columns? > > Thanks, > j. > > > -- > ...................... > ..... Jason C. Leach > .. > > Current PGP/GPG Key ID: 43AD2024 > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-> r-help mailing list -- Readhttp://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html> Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
From: Petr Pikal <petr.pikal at precheza.cz> To: jleach at mail.ocis.net Subject: Re: [R] Manipulating Matricies Date sent: Fri, 26 Jul 2002 13:26:29 +0200 On 25 Jul 2002 at 15:22, Jason C. Leach wrote:> hi, > > If I have a table of data, from read.table or scan how can I > extract various columns to create a matrix? And once I have thesee ?as.matrix and [] parentheses help e.g. my.matrix <- as.matrix(daf[,c(1:3,5,9)]) will construct a matrix from colunms 1-3,5 and 9 and similar approach you can use on matrices> matrix, how can I add and remove columns?my.matrix <- my.matrix[,-5] will give you matrix without column 5> > Thanks, > j. > > > -- > ...................... > ..... Jason C. Leach > .. > > Current PGP/GPG Key ID: 43AD2024 > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. > -. -.-.-.-.- r-help mailing list -- Read > http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", > or "[un]subscribe" (in the "body", not the subject !) To: > r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. > _. _._._._._Petr Pikal petr.pikal at precheza.cz p.pik at volny.cz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._