r - Conditionally rename the value depending on the previous row -


i have data frame df:

event       code picture     no$ picture     value picture     $ picture     value picture     no$ picture     value picture     no$ picture     value picture     $ picture     value 

i want rename value reward or no_reward depending on previous row. if it's $ reward, if it's no$ no_reward

what best way it?

another idea,

df1$code[c(false, true)] <- ifelse(df1$code[c(true, false)] == 'no$', 'no_reward', 'reward') df1 #     event      code #1  picture       no$ #2  picture no_reward #3  picture         $ #4  picture    reward #5  picture       no$ #6  picture no_reward #7  picture       no$ #8  picture no_reward #9  picture         $ #10 picture    reward 

note: assumes every $ or no$, value follows


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -