[R] Neighbour List to Matrix

A J anxusgo at hotmail.com
Fri Feb 17 20:19:34 CET 2012


I don't know why data are not well shown... I have attached a PDF file to this message with the structure of the begining list and the final matrix one. I think I have no explain the issue in a right way. Sorry for the inconveniences. The last thing I want is to disturb with technical questions...
Best,
AJ

> Date: Fri, 17 Feb 2012 13:49:40 -0500
> Subject: Re: [R] Neighbour List to Matrix
> From: jholtman en gmail.com
> To: anxusgo en hotmail.com
> CC: r-help en r-project.org
> 
> Is this what you are after:
> 
> > x <- read.table(text = "ID1   IDP2   SUMVAL
> + 1   56   0.065935895
> + 1   900   0.044110185
> + 1   1409   0.196314197
> + 3   4   0.071320388
> + 3   83   0.016269564
> + 3   529   0.011359239
> + 3   883   0.012242533
> + 3   1242   0.016558924
> + 4   3   0.004307024
> + 4   7   0.004699821
> + 4   16   0.004735112
> + 5   7   0.010324926
> + 5   16   0.011250504
> + 5   498   0.009709858
> + 5   502   0.004775749
> + 5   508   0.031411560", header = TRUE)
> >
> > str(x)  # dataframe
> 'data.frame':   16 obs. of  3 variables:
>  $ ID1   : int  1 1 1 3 3 3 3 3 4 4 ...
>  $ IDP2  : int  56 900 1409 4 83 529 883 1242 3 7 ...
>  $ SUMVAL: num  0.0659 0.0441 0.1963 0.0713 0.0163 ...
> > x.m <- as.matrix(x)
> > str(x.m) # matrix
>  num [1:16, 1:3] 1 1 1 3 3 3 3 3 4 4 ...
>  - attr(*, "dimnames")=List of 2
>   ..$ : NULL
>   ..$ : chr [1:3] "ID1" "IDP2" "SUMVAL"
> > head(x.m)
>      ID1 IDP2     SUMVAL
> [1,]   1   56 0.06593589
> [2,]   1  900 0.04411019
> [3,]   1 1409 0.19631420
> [4,]   3    4 0.07132039
> [5,]   3   83 0.01626956
> [6,]   3  529 0.01135924
> 
> At this point you could use 'wrtie.csv' to create a CSV file.
> 
> On Fri, Feb 17, 2012 at 1:42 PM, A J <anxusgo en hotmail.com> wrote:
> > Sorry too much. I was convinced it was able to view well. So, the structure
> > of my data set is something like this:
> >
> >
> > ID1   IDP2   SUMVAL
> >
> > 1   56   0.065935895
> > 1   900   0.044110185
> > 1   1409   0.196314197
> > 3   4   0.071320388
> > 3   83   0.016269564
> > 3   529   0.011359239
> > 3   883   0.012242533
> > 3   1242   0.016558924
> > 4   3   0.004307024
> > 4   7   0.004699821
> > 4   16   0.004735112
> > 5   7   0.010324926
> > 5   16   0.011250504
> > 5   498   0.009709858
> > 5   502   0.004775749
> > 5   508   0.031411560
> > ...
> >
> >
> > Summarizing: I have all data recorded in a TXT file, and I would like, after
> > loading in R, transform this list into a matrix (complete matrix, not half)
> > in order to export to CSV or TXT finally.
> > Thank you very much for everything.
> > Best,
> > AJ
> >
> >> Date: Fri, 17 Feb 2012 13:12:55 -0500
> >> Subject: Re: [R] Neighbour List to Matrix
> >> From: jholtman en gmail.com
> >> To: anxusgo en hotmail.com
> >> CC: r-help en r-project.org
> >>
> >> You might want to post a better example of what your data looks like.
> >> In the email, it is hard to tell how to split the data into rows that
> >> can be read with three fields since it looks like the data is composed
> >> of pairs of numbers.
> 
> 
> 
> -- 
> Jim Holtman
> Data Munger Guru
> 
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
 		 	   		  
------------ pr?xima parte ------------
A non-text attachment was scrubbed...
Name: sample.pdf
Type: application/pdf
Size: 5356 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120217/2dca10ee/attachment.pdf>


More information about the R-help mailing list