I want to reshape iris data in R from 5 columns to 4 columns. The final output should be have columns:
- Species
- Part
- Length
- Width
The 'Part' column should include 'Petal' and 'Sepal'
The code which I tried as below gave an error "Error: Duplicate identifiers for rows"
iris_new <- iris[c(5, 1:4)] %>%
gather(part_measure, value, -Species) %>%
separate(part_measure, c("part", "measure"), "[.]") %>%
spread(measure, value)
Please correct me, thanks in advance.