0

I have this dataset: http://media.sdsoybean.org/images/Uploads/2016%20South%20Dakota%20Soybean%20Yield%20Contest%20Results.pdf

I want to make a new vector called Method. This will consist of the values No-till, Non-irrigated or Irrigated. I can extract these from group Group column.

I'm thinking an ifelse() function combined with grepl() or strsplit() might work?

Thanks.

  • Can you make a self-contained example please? Like `x <- c("Group 0 Non-Irrigated", "Group 0 No-Till")` etc etc... with data representative of each of the possibilities. It's a fair enough question, but it will be useless when the pdf gets moved or deleted. – thelatemail Jul 05 '17 at 23:20
  • I tried this: `Method <- ifelse(grepl(value1, YieldContests$Group)=="TRUE","No-till", ifelse(grepl(value2, YieldContests$Group)=="TRUE","Non-irrigated", ifelse(grepl(value3, YieldContests$Group)=="TRUE","Irrigated",NA) ) )` – David Sturdevant Jul 05 '17 at 23:21
  • Here's the values. `value1<-"Non-till" value2<-"Non-irrigated" value3<-"Irrigated"` – David Sturdevant Jul 05 '17 at 23:23
  • `sapply(strsplit(YieldContests$Group, " "), tail, 1)` since your values are always at the end of the variable I think – thelatemail Jul 05 '17 at 23:52

0 Answers0