[R] restructuring matrix
Hi all, let's say I have matrix PeopleDescValue Mary Height50 Mary Weight 100 FannyHeight 60 Fanny Height200 Is there a quick way to form the following matrix? People HeightWeight Mary 50 100 Fanny 60200 (Assuming I don't know the length of people/desc and let's say these are characters matrix.. I tried play with row(), col(), etc.. but I don't seem to find like a duplicate match function... I'm trying to write some one/two liner that convert my resulting matrix to vector and pick the appropriate fields.. etc ) Thanks! -- View this message in context: http://www.nabble.com/restructuring-matrix-tf3991741.html#a11334950 Sent from the R help mailing list archive at Nabble.com. __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] restructuring matrix
If your original matrix is A then unique(A$People) and unique(A$Desc) will produce a vector of different people and a vector of different descriptions. --- yoo [EMAIL PROTECTED] wrote: Hi all, let's say I have matrix PeopleDescValue Mary Height50 Mary Weight 100 FannyHeight 60 Fanny Height200 Is there a quick way to form the following matrix? People HeightWeight Mary 50 100 Fanny 60200 (Assuming I don't know the length of people/desc and let's say these are characters matrix.. I tried play with row(), col(), etc.. but I don't seem to find like a duplicate match function... I'm trying to write some one/two liner that convert my resulting matrix to vector and pick the appropriate fields.. etc ) Thanks! -- View this message in context: http://www.nabble.com/restructuring-matrix-tf3991741.html#a11334950 Sent from the R help mailing list archive at Nabble.com. __ R-help@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 and provide commented, minimal, self-contained, reproducible code. __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] restructuring matrix
Yea... let's say I constructed a matrix with rownames/colnames be those unique elements.. then what should I do? I don't want to do mapply, etc to find the field.. I'm wondering if there's a smarter way using row/col.. etc... Thanks! Moshe Olshansky-2 wrote: If your original matrix is A then unique(A$People) and unique(A$Desc) will produce a vector of different people and a vector of different descriptions. --- yoo [EMAIL PROTECTED] wrote: Hi all, let's say I have matrix PeopleDescValue Mary Height50 Mary Weight 100 FannyHeight 60 Fanny Height200 Is there a quick way to form the following matrix? People HeightWeight Mary 50 100 Fanny 60200 (Assuming I don't know the length of people/desc and let's say these are characters matrix.. I tried play with row(), col(), etc.. but I don't seem to find like a duplicate match function... I'm trying to write some one/two liner that convert my resulting matrix to vector and pick the appropriate fields.. etc ) Thanks! -- View this message in context: http://www.nabble.com/restructuring-matrix-tf3991741.html#a11334950 Sent from the R help mailing list archive at Nabble.com. __ R-help@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 and provide commented, minimal, self-contained, reproducible code. __ R-help@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 and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/restructuring-matrix-tf3991741.html#a11335437 Sent from the R help mailing list archive at Nabble.com. __ R-help@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 and provide commented, minimal, self-contained, reproducible code.
Re: [R] restructuring matrix
Is this what you want? x - PeopleDescValue + Mary Height50 + Mary Weight 100 + FannyHeight 60 + Fanny Weight200 x - read.table(textConnection(x), header=TRUE, as.is=TRUE) reshape(x, direction='wide', idvar=People, timevar=Desc) People Value.Height Value.Weight 1 Mary 50 100 3 Fanny 60 200 On 6/27/07, yoo [EMAIL PROTECTED] wrote: Hi all, let's say I have matrix PeopleDescValue Mary Height50 Mary Weight 100 FannyHeight 60 Fanny Height200 Is there a quick way to form the following matrix? People HeightWeight Mary 50 100 Fanny 60200 (Assuming I don't know the length of people/desc and let's say these are characters matrix.. I tried play with row(), col(), etc.. but I don't seem to find like a duplicate match function... I'm trying to write some one/two liner that convert my resulting matrix to vector and pick the appropriate fields.. etc ) Thanks! -- View this message in context: http://www.nabble.com/restructuring-matrix-tf3991741.html#a11334950 Sent from the R help mailing list archive at Nabble.com. __ R-help@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 and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]] __ R-help@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 and provide commented, minimal, self-contained, reproducible code.