Is it possible to restrict a data frame to a specific row and then change some values in one of the columns?
Let's say I calculate GROWTH as (SIZE_t+1 - SIZE_t)/SIZE_t and now I can see that there are some strange values for GROWTH (e.g. 1000) and the reason is a corrupt value of the corresponding SIZE variable. Now I'd like to find and replace the corrupt value of SIZE.
If I type:
data <- mutate(filter(data, lead(GROWTH)==1000), SIZE = 2600)
then only the corrupt row is stored in data and the rest of my data frame is lost.
What I'd like to do instead is filter "data" on the left hand side to the corresponding row of the corrupt value and then mutate the incorrect variable (on the right hand side):
filter(data, lead(GROWTH)==1000) <- mutate(filter(data, lead(GROWTH)==1000), SIZE = 2600)
but that doesn't seem to work. Is there a way to handle this using dplyr? Many thanks in advance