Turn dataset to matrix and keep the "sample" column to run prcomp in R

32 views Asked by At

I have a dataset that looks like this:

sample area trnsp
a 2,455 134,23
b 2,009 176,32
c 1,997 200,01
d 2,309 149,87

If I run prcomp(data) I will get a must be numeric error because the sample column is a character. I was thinking turn in it into a matrix but then the sample column is turned into a factor and assigned a number. I was wondering if it is possible to convert the data into a matrix with this form:

area trnsp
a 2,455 134,23
b 2,009 176,32
c 1,997 200,01
d 2,309 149,87

I am very sorry if this has been asked before I search and only find the ones that turn datasets into matrix assigning a numeric value to the character column

Thank you for all your help

1

There are 1 answers

2
Roman Luštrik On

Turn sample names into rownames and remove the column name.