1

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 Answers1

1

Turn sample names into rownames and remove the column name.

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • Thanks for the fast reply. The columns area and trnsp are recognized as numeric but the sample column is chr, that is why prcomp doesn't run. that is why I would like to make a matrix to maybe solve the problem and keep the sample names to use when I plot it – Gonzalo de Quesada Nov 16 '22 at 10:27
  • 2
    In that case, make sample names rownames and remove the column. – Roman Luštrik Nov 16 '22 at 10:44