The documentation for tidyr suggests that gather and spread are transitive, but the following example with the "iris" data shows they are not, but it is not clear why. Any clarification would be greatly appreciated
iris.df = as.data.frame(iris)
long.iris.df = iris.df %>% gather(key = feature.measure, value = size, -Species)
w.iris.df = long.iris.df %>% spread(key = feature.measure, value = size, -Species)
I expected the data frame "w.iris.df" to be the same as "iris.df" but received the following error instead:
"Error: Duplicate identifiers for rows (1, 2, 3, 4, 5, 6, 7, 8, 9..."
My general question is how to reverse an application of "gather" on this sort of dataset.
iris.df$row <- 1:nrow(iris.df)
– hadley