I am working with a dataset from a herbicide experiment involving different herbicides and their ratings. I'm trying to use tidyr to manipulate the data. Here's what I'm working with:
library(readr)
library(tidyr)
library(dplyr)
plot <- c("101","102","103","104")
herbicide <- c("mesotrione","tembotrione","mesotrione","tembotrione")
plant_1 <- c("100","100","95","95")
plant_2 <- c("100","100","95","20")
plant_3 <- c("50","50","50","50")
plant_4 <- c("40","40","30","30")
dataframe1<- as.data.frame(cbind(plot, herbicide, plant_1, plant_2, plant_3,
plant_4))
I want to manipulate this data so that I will have the data sorted in columns as follows:
plot <-
c("101","101","101","101","102","102","102","102","103","103","103","103","104","104","104","104")
herbicide <-
c("mesotrione","mesotrione","mesotrione","mesotrione","tembotrione","tembotrione","tembotrione","tembotrione",
"mesotrione","mesotrione","mesotrione","mesotrione","tembotrione","tembotrione","tembotrione","tembotrione")
plant <- c("1","2","3","4","1","2","3","4","1","2","3","4","1","2","3","4")
score <-
c("100","100","95","95","100","100","95","20","50","50","50","50","40","40","30","30")
dataframe2 <- as.data.frame(cbind(plot, herbicide, plant, score))
This is what I have tried, but it doesn't work for me:
sort <- gather(data1, plot, plant_score, herbicide)
Any help would be greatly appreciated, thanks everyone!