Re: [R] reshape non-square matrix

2014-03-04 Thread Chirag Gupta
This takes away names of all the variables


On Sat, Mar 1, 2014 at 9:30 AM, arun smartpink...@yahoo.com wrote:



 Hi,
 You could try:
 #If mat1 is the matrix
 dimnames(mat1) - list(1:nrow(mat1),1:ncol(mat1))
 setNames(as.data.frame.table(mat1),c(m,n,value))
 A.K.


 On Friday, February 28, 2014 11:40 PM, Chirag Gupta cxg...@email.uark.edu
 wrote:
 Hi list

 I have a matrix of size m x n (m and n are different, hence non square!)
 I want to melt it in such a way that I get a df of 3 columns. m ,n and cell
 value in the original matrix.

 Any suggestions?

 --
 *Chirag Gupta*
 Department of Crop, Soil, and Environmental Sciences,
 115 Plant Sciences Building, Fayetteville, Arkansas 72701

 [[alternative HTML version deleted]]

 __
 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.




-- 
*Chirag Gupta*
Department of Crop, Soil, and Environmental Sciences,
115 Plant Sciences Building, Fayetteville, Arkansas 72701

[[alternative HTML version deleted]]

__
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] reshape non-square matrix

2014-03-04 Thread arun




Hi,
You didn't provide any reproducible example to start with.
Using Jeff's example

mx - matrix( 1:12, nrow=3 )
dimnames(mx) - list(1:nrow(mx),1:ncol(mx)) ##
setNames(as.data.frame.table(mx),c(m,n,value))

  m n value
1  1 1 1
2  2 1 2
3  3 1 3
4  1 2 4
5  2 2 5
6  3 2 6
7  1 3 7
8  2 3 8
9  3 3 9
10 1 4    10
11 2 4    11
12 3 4    12

mx1 - 
matrix(1:12,nrow=3,ncol=4,dimnames=list(1:3,c(Col1,Col2,Col3,Col4)))


setNames(as.data.frame.table(mx1),c(m,n,value))
   m    n value
1  1 Col1 1
2  2 Col1 2
3  3 Col1 3
4  1 Col2 4
5  2 Col2 5
6  3 Col2 6
7  1 Col3 7
8  2 Col3 8
9  3 Col3 9
10 1 Col4    10
11 2 Col4    11
12 3 Col4    12

A.K.



On Tuesday, March 4, 2014 9:39 PM, Chirag Gupta cxg...@email.uark.edu wrote:

This takes away names of all the variables



On Sat, Mar 1, 2014 at 9:30 AM, arun smartpink...@yahoo.com wrote:



Hi,
You could try:
#If mat1 is the matrix
dimnames(mat1) - list(1:nrow(mat1),1:ncol(mat1))
setNames(as.data.frame.table(mat1),c(m,n,value))
A.K.



On Friday, February 28, 2014 11:40 PM, Chirag Gupta cxg...@email.uark.edu 
wrote:
Hi list

I have a matrix of size m x n (m and n are different, hence non square!)
I want to melt it in such a way that I get a df of 3 columns. m ,n and cell
value in the original matrix.

Any suggestions?

--
*Chirag Gupta*

Department of Crop, Soil, and Environmental Sciences,
115 Plant Sciences Building, Fayetteville, Arkansas 72701

    [[alternative HTML version deleted]]

__
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.




-- 
Chirag Gupta
Department of Crop, Soil, and Environmental Sciences,
115 Plant Sciences Building, Fayetteville, Arkansas 72701

__
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] reshape non-square matrix

2014-03-04 Thread Chirag Gupta
Jeff

This works fine for smaller ones but I have a big dataframe. Its ~35000 X
30. When I try this command, it says Using  as id variables.

Thank you.


On Sat, Mar 1, 2014 at 12:38 AM, Jeff Newmiller jdnew...@dcn.davis.ca.uswrote:

 library(reshape2)
 mx - matrix( 1:12, nrow=3 )
 mxdf - melt( mx )
 names( mxdf ) - c( m, n, value )

 ---
 Jeff NewmillerThe .   .  Go Live...
 DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live
 Go...
   Live:   OO#.. Dead: OO#..  Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
 /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.

 On February 28, 2014 5:49:26 PM PST, Chirag Gupta cxg...@email.uark.edu
 wrote:
 Hi list
 
 I have a matrix of size m x n (m and n are different, hence non
 square!)
 I want to melt it in such a way that I get a df of 3 columns. m ,n and
 cell
 value in the original matrix.
 
 Any suggestions?




-- 
*Chirag Gupta*
Department of Crop, Soil, and Environmental Sciences,
115 Plant Sciences Building, Fayetteville, Arkansas 72701

[[alternative HTML version deleted]]

__
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] reshape non-square matrix

2014-03-04 Thread Jeff Newmiller

On Tue, 4 Mar 2014, Chirag Gupta wrote:


Jeff
This works fine for smaller ones but I have a big dataframe. Its ~35000 X 30. 
When I try this command,
it says Using  as id variables.

Thank you.


You asked for a solution regarding a matrix. Now you talk about data 
frames. And in responding to Arun you have complained that it takes away 
the names of the variables, leading me to question whether you really 
want what you have asked for because the m,n,value format has no room 
for the original names. (There are potential solutions to that problem, 
but they are outside of the scope of your original question.)


Since you apparently don't know the difference between a matrix and a data 
frame, I will pass on responding further to this thread until you provide 
a reproducible example.  This is because there are several potential 
problems introduced by applying this algorithm to arbitrary data frames. 
You should (re)read the Introduction to R regarding data frames and 
matrices (note particularly that each column of a data frame can be of a 
different type), and you should read [1] paying particular attention to 
how small amounts of sample data can be provided in your reproducible 
example.


Also, please read the Posting Guide mentioned at the bottom of this email. 
In particular, that document requests that you NOT use HTML email format 
because what we see is usually not what you saw when you do that (which 
makes it very hard to understand what you are trying to tell us).


[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example



On Sat, Mar 1, 2014 at 12:38 AM, Jeff Newmiller jdnew...@dcn.davis.ca.us 
wrote:
  library(reshape2)
  mx - matrix( 1:12, nrow=3 )
  mxdf - melt( mx )
  names( mxdf ) - c( m, n, value )

  
---
  Jeff Newmiller                        The     .       .  Go 
Live...
  DCN:jdnew...@dcn.davis.ca.us        Basics: ##.#.       ##.#.  Live 
Go...
                                        Live:   OO#.. Dead: OO#..  Playing
  Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
  /Software/Embedded Controllers)               .OO#.       .OO#.  
rocks...1k
  
---
  Sent from my phone. Please excuse my brevity.

  On February 28, 2014 5:49:26 PM PST, Chirag Gupta cxg...@email.uark.edu 
wrote:
  Hi list
  
  I have a matrix of size m x n (m and n are different, hence non
  square!)
  I want to melt it in such a way that I get a df of 3 columns. m ,n and
  cell
  value in the original matrix.
  
  Any suggestions?




--
Chirag Gupta
Department of Crop, Soil, and Environmental Sciences,
115 Plant Sciences Building, Fayetteville, Arkansas 72701




---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---__
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] reshape non-square matrix

2014-03-01 Thread arun


Hi,
You could try:
#If mat1 is the matrix
dimnames(mat1) - list(1:nrow(mat1),1:ncol(mat1))
setNames(as.data.frame.table(mat1),c(m,n,value))
A.K.


On Friday, February 28, 2014 11:40 PM, Chirag Gupta cxg...@email.uark.edu 
wrote:
Hi list

I have a matrix of size m x n (m and n are different, hence non square!)
I want to melt it in such a way that I get a df of 3 columns. m ,n and cell
value in the original matrix.

Any suggestions?

-- 
*Chirag Gupta*
Department of Crop, Soil, and Environmental Sciences,
115 Plant Sciences Building, Fayetteville, Arkansas 72701

    [[alternative HTML version deleted]]

__
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] reshape non-square matrix

2014-02-28 Thread Rolf Turner


On 01/03/14 14:49, Chirag Gupta wrote:


Hi list

I have a matrix of size m x n (m and n are different, hence non square!)
I want to melt it in such a way that I get a df of 3 columns. m ,n


   Surely you mean i, j (i = 1, ..., m), j = 1, ..., n).


and cell
value in the original matrix.


Yes:

dfX - data.frame(i=as.vector(row(X)),j=as.vector(col(X)),
  value=as.vector(X))

where X is your matrix.  The fact that X is non-square is of course 
completely irrelevant.


cheers,

Rolf Turner

__
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] reshape non-square matrix

2014-02-28 Thread Jeff Newmiller
library(reshape2)
mx - matrix( 1:12, nrow=3 )
mxdf - melt( mx )
names( mxdf ) - c( m, n, value )

---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On February 28, 2014 5:49:26 PM PST, Chirag Gupta cxg...@email.uark.edu wrote:
Hi list

I have a matrix of size m x n (m and n are different, hence non
square!)
I want to melt it in such a way that I get a df of 3 columns. m ,n and
cell
value in the original matrix.

Any suggestions?

__
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.