library(tidyr) #Converting a wide dataset into long dataset
long_data <- gather(table2,
key="variable",
value="value",
year:count)
as.data.frame(long_data)
#Converting the above long data set to a wide dataset again
wide_data <- spread(long_data, variable, value) -----> This is where I'm facing errors
library(tidyr) #Converting a wide dataset into long dataset
long_data <- gather(table2,
key="variable",
value="value",
year:count)
as.data.frame(long_data)
#Converting the above long data set to a wide dataset again
wide_data <- spread(long_data, variable, value) -----> This is where I'm facing errors.
The problem is that there are identical rows in the long_data. At the first glance, you see that the rows 1 and 2, 3 and 4, 5 and 6, so on are all the same. When you try to convert this data frame into a wide format, it gets confused. In other words, the problem lies not in the last command but in the code creating the long_data.