[R] re ading transposed data in read.csv

Dieter Menne dieter.menne at menne-biomed.de
Sat Aug 15 09:20:04 CEST 2009




sandsky wrote:
> 
> I have a data set (csv); e.g.,
> 
> ID  samp1  samp2 samp3 samp4
> G1       23        32      12      87
> G2       85        45      49      76
> G3       12        46      39      28
> G4       73        26      18      13
> 
> and read it:
> 
> data1<-(read.csv("Datafolder/rawdata.csv",header=T))
> 
> It is fine with reading as above, but, if it is read as transposed values
> like:
> 
> data1<-t(read.csv("Datafolder/rawdata.csv",header=T))
> 
> ID         "G1"   "G2"   "G3"   "G4"
> samp1   "23"    "85"    "12"   "73"
> ...
> 
> all values are shown in "   ".
> 
> How to get this transposed data as numerical values?
> 
> 

Because ID is not numeric, and in a data frame each column must have the
same data type. The least common denominator is "character".

Written explicitly, you have to transpose the numeric part, and paste in the
names later. This could be shortened, but the example below gives the idea.

Dieter

d = data.frame(ID=c("G1","G2"), samp1=1:2,samp2=5:6)
d
t(d)
dt = as.data.frame(t(d[-1]))
names(dt)= d[,1]



-- 
View this message in context: http://www.nabble.com/reading-transposed-data-in-read.csv-tp24979445p24982142.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list