Hi all, Suppose I have the following matrix which is a constant matrix I've copied from some other document: 1.2 3.4 1.4 ... 2.3 3.7 2.6 ... ... How do I make it into a matrix or array in R? What is the fastest way of initializing a constant matrix with this copy/pasted values? Thanks a lot! [[alternative HTML version deleted]]
Sorry Michael, but I don't understand your question. If you want to intialize a constant matrix (there is not such thing in R, just create a numerical matrix and use it without changing its values), you just use matrix(). For help and arguments of the function, type: > ?matrix Best, Philippe Grosjean Michael wrote:> Hi all, > > Suppose I have the following matrix which is a constant matrix I've copied > from some other document: > > 1.2 3.4 1.4 ... > 2.3 3.7 2.6 ... > ... > > How do I make it into a matrix or array in R? > > What is the fastest way of initializing a constant matrix with this > copy/pasted values? > > Thanks a lot! > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >
> Suppose I have the following matrix which is a constant matrix I've copied > from some other document: > > 1.2 3.4 1.4 ... > 2.3 3.7 2.6 ... > ... > How do I make it into a matrix or array in R? > What is the fastest way of initializing a constant matrix with this > copy/pasted values?you cannot just paste it, you have to adapt it either like this x <- matrix( c( 1.2, 3.4, 1.4, 2.3, 3.7, 2.6 ), nrow = 2, byrow = TRUE) or like this: x <- rbind( c( 1.2, 3.4, 1.4 ), c( 2.3, 3.7, 2.6 ) ) The second is closer to ML's x = [1,2 3.4 1.4;2.3 3.7 2.6] but the first is probably the more popular/recommended approach. If it's a large matrix that you don't want to adapt manually I think the only way is to go via an ascii text file. I see that you come from Matlab and that you have asked some rather basic questions. I really recommend you, that you read the manuals (as indicated). And do read them 2 or 3 times as they are much denser than the Matlab manuals. If you are not able to attend a course (which IMHO is the best way to learn R) I'd buy a book. (http://www.r-project.org/doc/bib/R-publications.html). Maybe the "John Verzani. Using R for Introductory Statistics" or "Uwe Ligges. Programmieren mit R" could help you. Best regards, Hans-Peter
Do you mean they are in the clipboard in the format shown? If that is the case then do this: as.matrix(read.table("clipboard")) On 1/30/06, Michael <comtech.usa at gmail.com> wrote:> Hi all, > > Suppose I have the following matrix which is a constant matrix I've copied > from some other document: > > 1.2 3.4 1.4 ... > 2.3 3.7 2.6 ... > ... > > How do I make it into a matrix or array in R? > > What is the fastest way of initializing a constant matrix with this > copy/pasted values? > > Thanks a lot! > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Maybe Matching Threads
- R - MATLAB apply like function
- Is there a R function that can do similar things like 'pdist' in Matlab?
- [LLVMdev] How to reduce the footprint of MDNodes? (About the comment you made at BOF LTO)
- [Fwd: RedHat 7.0, Wine en Matlab: een fontprobleem??]
- [LLVMdev] How to reduce the footprint of MDNodes? (About the comment you made at BOF LTO)