[R] help getting data in correct format

Benjamin B. benj.bad.ac at googlemail.com
Mon Dec 6 16:57:22 CET 2010


When I try to read data from excel, I save it in csv-format and read the files via:

fileData  <-read.csv(fkFileName, header = fkHasHeader, stringsAsFactors=FALSE, sep=fkSep)

where fkSep is depending on your localization of excel (I think).
For some columns that don’t get the correct data format on import I use

fileData[,col]   <-as.<dataType>(fileData[,col])

Maybe you can use read.csv2 if you have a german (or european) excel.

Benjamin B.
Hamburg, Germany


-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im Auftrag von John Haart
Gesendet: Montag, 6. Dezember 2010 15:54
An: r-help at r-project.org
Betreff: [R] help getting data in correct format

>> Dear All,
>>
>> I am having trouble getting my data into R as i need it! I am used to using read.delim("") to open .txt files to do work on. The function i am using requires a matrix like the one below.
>>
>> My data is from excel and then saved as a txt file. I have tried the usual read.delim("") approach but the function doesn't like it, i have also tried as.matrix(data =) but that doesn't work.
>>
>> What i require is the row names to be the first column of the txt file , as below
>>
>> This was made using this
>>
>> nTraits = 5
>> nSpecies = 20
>> a=matrix(runif(nTraits*nSpecies),nSpecies,nTraits)
>> rownames(a) = letters[1:nSpecies]
>>
>> However i want my data in their not simulated
>>
>>
>>
>>
>>      [,1]       [,2]       [,3]        [,4]       [,5]
>> a 0.72869780 0.36399621 0.82468338 0.850754150 0.76943833
>> b 0.12871015 0.85622370 0.82368054 0.108350500 0.79933805
>> c 0.66413022 0.24059396 0.74626595 0.748063466 0.14243494
>> d 0.54113172 0.97769199 0.10538211 0.184683363 0.29701420
>> e 0.44891743 0.38594751 0.01475637 0.492245059 0.87616253
>> f 0.09938324 0.62971605 0.79302032 0.156930575 0.09860269
>> g 0.30953025 0.35611074 0.70155464 0.149412029 0.26068831
>> h 0.15825945 0.43603713 0.23960806 0.617240274 0.97756739
>> i 0.56588912 0.34942257 0.51724529 0.360303540 0.78650285
>> j 0.96083252 0.44307860 0.17529919 0.007925761 0.51184681
>> k 0.09452434 0.49068549 0.80419267 0.401200731 0.70748547
>> l 0.26930842 0.65879761 0.76251526 0.315836610 0.72541148
>> m 0.52158352 0.77047295 0.81276164 0.641264799 0.83530547
>> n 0.21039165 0.63698953 0.94877972 0.329354647 0.08512338
>> o 0.80294849 0.85471292 0.75379324 0.310917453 0.71528901
>> p 0.01494773 0.03056341 0.91496579 0.817269310 0.29831036
>> q 0.56848121 0.50864998 0.59944638 0.046270295 0.24808518
>> r 0.30511696 0.79790561 0.83210599 0.334429013 0.50195706
>> s 0.96551698 0.95807309 0.26016434 0.629840741 0.47213370
>> t 0.86062917 0.09867528 0.24388087 0.167937283 0.70620760
>>
>> Thanks
______________________________________________
R-help at 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.



More information about the R-help mailing list