[R] combine variables to matrix
I just got stuck with a quite simple question. I've just read in an ASCII table from a plain text file with read.table(). It's a 1200x1200 table. R has assigned variables for each column: V1,V2,V3,V4,... For small data sets data - read.table(data.txt); data.matrix - cbind(V1,V2,V3); works. But how could I put together 1200 columns? I've searched the R mailing help and stumbled upon this entry: https://stat.ethz.ch/pipermail/r-help/2007-July/137121.html which doesn't help me. thanks for your help. andre __ 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] combine variables to matrix
Andre Jung wrote: I just got stuck with a quite simple question. I've just read in an ASCII table from a plain text file with read.table(). It's a 1200x1200 table. R has assigned variables for each column: V1,V2,V3,V4,... For small data sets data - read.table(data.txt); data.matrix - cbind(V1,V2,V3); as.matrix(data) ? (or, if you know the dimensions, M - matrix(scan(data.text), 1200, 1200) ) works. But how could I put together 1200 columns? I've searched the R mailing help and stumbled upon this entry: https://stat.ethz.ch/pipermail/r-help/2007-July/137121.html which doesn't help me. thanks for your help. andre __ 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. -- O__ Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] combine variables to matrix
Hi Andre, I don't quite understand what you are trying to do. Why you are using cbind to join columns of a dataset that it is already in table form? It is true that read.table will give you a data.frame instead of a matrix, but if for some reason you need a matrix you can do simply data.matrix=as.matrix(data) Julian Andre Jung wrote: I just got stuck with a quite simple question. I've just read in an ASCII table from a plain text file with read.table(). It's a 1200x1200 table. R has assigned variables for each column: V1,V2,V3,V4,... For small data sets data - read.table(data.txt); data.matrix - cbind(V1,V2,V3); works. But how could I put together 1200 columns? I've searched the R mailing help and stumbled upon this entry: https://stat.ethz.ch/pipermail/r-help/2007-July/137121.html which doesn't help me. thanks for your help. andre __ 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.
Re: [R] combine variables to matrix
You can always make a loop (V1 corresponds to column 1, etc.) but as.matrix() is simpler, i.e. in your case data.matrix - as.matrix(data) --- Andre Jung [EMAIL PROTECTED] wrote: I just got stuck with a quite simple question. I've just read in an ASCII table from a plain text file with read.table(). It's a 1200x1200 table. R has assigned variables for each column: V1,V2,V3,V4,... For small data sets data - read.table(data.txt); data.matrix - cbind(V1,V2,V3); works. But how could I put together 1200 columns? I've searched the R mailing help and stumbled upon this entry: https://stat.ethz.ch/pipermail/r-help/2007-July/137121.html which doesn't help me. thanks for your help. andre __ 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.