I find myself struggling with data import for further nMDS and Bioenv analysis with "vegan" and "ggplot2". I have a data frame "Taxa" that looks like this (the values are there to mean it is "numeric". —
head(Taxa)
X1 Station1 Stations1_2 Stations1_3 ... Species1 123 456 789 Species2 123 456 789 Species3 123 456 789
...
After I transpose my data to have the stations (observations) as rows
Taxa <- t(Taxa)
X_1 Species1 Species2 Species3 ...
Station1 123 456 789
Species1_2 123 456 789
Species1_3 123 456 789
...
Now if I check how the data has been transposed I see that it has been converted into a "matrix"
class(Taxa) [1] "matrix"
Now I can change again the matrix into a data frame
Taxa.df <- data.frame(Taxa)
And what I get then is the following:
head(Taxa.df)
X1 X2 X3
X_1 Species1 Species2 Species3 ...
Station1 123 456 789
Species1_2 123 456 789
Species1_3 123 456 789
...
Now what I would need is to get the first row to become the columns header so that I can restore the initial structure
colnames(Taxa.df)=Taxa.df[1,]
When I do this this happens to the data frame
23 10 16 ....
X_1 Species1 Species2 Species3 ...
Station1 123 456 789
Species1_2 123 456 789
Species1_3 123 456 789
...
I don't manage to get to have the first row as header.
If I can't do this I can't run the transformation I need and all the stats analysis I still need to run. I spent the whole day simply trying to import the data from xlsx on Rstudio for Mac and solve this issue. I hope you guys can help. I did already look around a lot and mostly thought to have found these two links as useful answers, but nothing solved my exact problem.
http://r.789695.n4.nabble.com/Transposing-Data-Frame-does-not-return-numeric-entries-td852889.html
Why does the transpose function change numeric to character in R?