I have this dataset, I want to add a new column for different ranges of number based on day. The ranges of number I am interested on are stored in v1 and v2.
ex <- data.frame('id'= seq(1:26),
'day'= c(105:115, 1:12,28:30),
'letter' = LETTERS[1:26],
s = rep(1:26, each = 3, len = 26) )
v1 <- c(107,112,10)
v2 <- c(109,115,28)
word <- c("pen","desk","light")
The column I want to add is stored in word. From day 107:109 I want to add the word "pen", 112:115 "desk", and 10:28 "light". For the rest of the values that fall outside of these ranges, I want to use the word "undetermined".
Yes, it is @FJCC! Thank you so much.
Since there is a bit of manual work, is there a way to replicate this string from 1:100, for example:
day >= v1[1] & day <= v2[1] ~ word[1]
The output I am looking for is something like:
day >= v1[1] & day <= v2[1] ~ word[1], day >= v1[2] & day <= v2[2] ~ word[2], day >= v1[3] & day <= v2[3] ~ word[3], day >= v1[4] & day <= v2[4] ~ word[4], day >= v1[5] & day <= v2[5] ~ word[5], . . . day >= v1[00] & day <= v2[100] ~ word[100],