Let's say I have the following dataset:
dat <- read.table(text="id_1 id_2
123 NA
456 NA
NA 3
NA 1
NA 1", header=T)
I'd like to change the id_1
value for the first row. I'd like to do something like this:
dat %>% slice(1) %>% mutate(id_1 == "new_id") %>% unslice()
However there doesn't appear to be an unslice
command, so I'm left with a dataframe that has a single row (the modified). Is there a clean way do get back the original dataset after modification in-place?
dplyr
I think the only method is using a combination ofmutate
andif_else
to specify the row/col to modify. see this