0

For example, I now have a dataframe

data = cbind(id = c(1,1,2,2,3,3),
             value = c('a', '','b', '', 'a', ''))

I want to expand things in the value column based on the column id. Something like this, where when id is 1, value will all be 'a':

data = cbind(id = c(1,1,2,2,3,3),
             value = c('a', 'a','b','b','a','a'))

Thank you!

roii
  • 1
  • 1
  • as i am not sure if the answer, for which the question was closed, is exactly what you are looking for i offer this option: `data = cbind.data.frame(id = c(1,1,2,2,3,3), value = c('a', '','b', '', 'a', ''))` `dat<-ifelse(data$id==1, data$value<-"a", "b")` you can nest the ifelse() should you want to change it depending on your id response like so: `dat<-ifelse(data$id==1, data$value<-"a", ifelse(data$id==2, "b", "a"))` – D.J Oct 12 '20 at 07:05
  • 1. `data = data.frame(id = c(1,1,2,2,3,3), value = c('a', '','b', '', 'a', ''))`. 2. `data[data == ''] <- NA`. 3. `data %>%group_by(id) %>% fill(value)` The solution needs `dplyr` and `tidyr`. – Ronak Shah Oct 12 '20 at 07:13

0 Answers0