[R] export/import matrix

Dieter Menne dieter.menne at menne-biomed.de
Mon Aug 1 09:51:06 CEST 2011


Rosario Garcia Gil-2 wrote:
> 
> I have a problem on keeping the format when I export a matrix file with
> the write.table() function.
> 
> When I import the data volcano from rgl package it looks like this in R:
> 
>> data[1:5,]
>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
> [,14]
> [1,]  100  100  101  101  101  101  101  100  100   100   101   101   102  
> 102
> [2,]  101  101  102  102  102  102  102  101  101   101   102   102   103  
> 103
> ...
> I use this data to represent a 3D map with the follwing script and it
> works PEFECT!
> 
>> y<- 2*data
>> x <- 10* (1:nrow(y))
>> z <- 10* (1:ncol(y))
>> ylim <- range(y)
>> ylen <-ylim[2] - ylim[1] + 1
>> colorlut <- terrain.colors(ylen)
>> col <- colorlut[y-ylim[1] + 1]
>> rgl.open()
>> rgl.surface(x,z,y, color=col, back="lines")
> ...
> Then I export it as write.table(data, file="datam.txt", row.names=TRUE,
> col.names=TRUE),
> ...
> when I import it back into R again with read.table("datam.txt") it looks
> like this in R:
> 
> ...
> The script I mention before does not anymore work on it, if I converted to
> matrix with as.matrix still does not work.
> 
> ...
> 

It is always better to report what str(mydata) looks like, instead of
showing the data. And I an quite sure that something like as.matrix would
work, but you did not tell use what the error message in "still does not
work" looked like.

Dieter




--
View this message in context: http://r.789695.n4.nabble.com/export-import-matrix-tp3708935p3709072.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list