I have a 2 column dataframe that I want to become 2 rows instead. The dimensions are 40 observations and 2 variables (whereas what I want is 40 variables and 1 observation, as I want the first row to become the column headers).
I have tried using reshape but I can't seem to get it right as I keep getting errors. Here is the dataframe that I am using:
Data.Label Test2
1 Family Petromyzontidae - lampreys
2 Species Ichthyomyzon castaneus
3 Taxonomic Authority Girard, 1858
4 Common Name(s) Chestnut Lamprey
5 French Name lamproie brune
6 OMNR Code 016
Test5 <- reshape(Test4, timevar = Test4$Data.Label, idvar = Test4$Test2,direction = "wide")
Error in `[.data.frame`(data, , idvar) : undefined columns selected
As mentioned, I've tried to use reshape. As there are 40 variables that I would like to become the column headers (Test4$Data.Label) I did not want to write out each one for the idvars. Is there another way to do this?
The desired result would be:
Family Species Taxonomic Authority Common Name(s) French Name OMNR Code
Petromyzontidae lampreys Ichthyomyzon castaneus Girard, 1858 Chestnut Lamprey lamproie brune 016
This way the Test4$Data.Label column becomes the column headers (40 in total) and the Test4$Test2 column becomes the 1st row.