[R] how to convert strings back to values?

Dave Roberts droberts at montana.edu
Thu Nov 10 01:04:38 CET 2005


Eszter,

I suspect the problem is different than you think.  It's possible that 
when you read in the data it assumed that the first column was data, not 
row names, and so when you transpose the first column becomes the first 
row. Since it is alpha, all the columns become factors rather then 
integers.  Check to see on the non-transposed matrix wheter the number 
of rows and columns is correct.  If it incorrectly treated the first 
column as data (as it would if you have the same number of column 
headings as columns), you could read it back in with

 > x <- read.table('file_name',header=TRUE, row.names=1)

and then transpose it

 > y <- t(x)

Often at that point the row and column names are stripped off, and you 
have to put them back.

 > y <- data.frame(y)
 > row.names(y) <- names(x)
 > names(y) <- row.names(x)

I'm interested in PCoA in ecology, so let me know how it goes.

HTH Dave

Francisco J. Zagmutt wrote:
> Examples of the code you used would have helped i.e. We don't know how 
> you transposed your matrix.  Did you use t()?  In any event, 
> as.integer() may be what you need.
> 
> Francisco
> 
> 
>> From: Illyes Eszter <illyese at freemail.hu>
>> To: r-help at stat.math.ethz.ch
>> Subject: [R] how to convert  strings back to values?
>> Date: Wed, 9 Nov 2005 21:55:44 +0100 (CET)
>>
>> Dear All,
>>
>> It's Eszter from Hungary, a total beginner with R. My problem is the
>> following:
>>
>> I have a dataset with binary values as a comma separated textfile. The
>> samples are in the coloumns and the species are in the rows.
>>
>> I have to transpose it for the further PCoA analysis. There is no
>> problem with reading the dataset.
>>
>> When I transpose the dataset, the original values become strings
>> (instead of 0,1,0,0,1 I have "0","1","0","0","1"). The distance matrix
>> cannot be counted from the transposed dataset, I have 2 error
>> messages:
>>
>> <Warning in vegdist(tdf1, method = "jaccard", binary = FALSE, diag =
>> FALSE,  : results may be meaningless because input data have
>> negative entries>
>>
>> <Error in rowSums(x, prod(dn), p, na.rm) : 'x' must be numeric>
>>
>> I do not understand the first, since I have only 1 and 0 in the 
>> dataset. I
>> guess I have the second because of the strings instead of values in the
>> dataset.
>>
>> Could you please help me solving these problems? I could not find
>> anything about these in the manuals.
>>
>> Thank you, cheers:
>>
>> Eszter
>>
>> p.s. This is a new problem, last week I worked with a similar dataset
>> and I did not get any error message like these.
>>
>>
>>
>> _____________________________________________________________________
>> Menõ csengõhangok (MP3 is!) és színes képek a mobilodra.
>> Nálunk szinte mindent megtalálsz, KLIKK IDE! www.7777oplogo.hu
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! 
>> http://www.R-project.org/posting-guide.html
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
David W. Roberts                                     office 406-994-4548
Professor and Head                                      FAX 406-994-3190
Department of Ecology                         email droberts at montana.edu
Montana State University
Bozeman, MT 59717-3460




More information about the R-help mailing list