I have a dataframe that I have successfully transposed using the t function present in base R. However I'd like to change the column names and row names to be part of the dataframe. I'll use the iris data as an example.
# Transpose iris data
iris.transposed <- t(iris)
# View the transposed DF
View(iris.transposed)
In the screenshot attached,
the column header in the transposed DF contains columns V1, V2, V2, V4, e.t.c. However, I'd like the row species to the the column header.
The same goes for the rows. Sepal.length, sepal.width, petal.length.. e.t.c are rownames. However, I'd like them to be part of the dataframe as observations.
How do I finalise this?
iris.transposed$setosato return? Note also that usingtconverts your data.frame to a matrix.make.unique()on the names by default. Why do you want this?colnames(iris.transposed) <- iris.transposed["Species", ]andiris.transposed$col <- rownames(iris.transposed)