I am trying to gather all of the columns in my data into a single column, except for one column that represents a grouping variable. For example, if using mini_iris:
mini_iris <- iris[c(1, 51, 101), ]
mini_iris
This is the closest I was able to get using gather():
mini_iris %>% gather(key = "Species", value = "Measurement")
But what I want is for the Species column to retain the species values from the original Species column. This way I still know which Species each measurement came from. This seems pretty simple but haven't been able to find a solution amazingly...
Thank you in advance for your time.
EDIT: The expected output should look like this:
mini_iris_long <-
data.frame(
Species = c(rep("setosa", 4),rep("versicolor", 4),rep("virginica", 4)),
Measurement = c(5.1,
3.5,
1.4,
0.2,
7.0,
3.2,
4.7,
1.4,
6.3,
3.3,
6.0,
2.5)
)
mini_iris_long