I have the following data.frame ::
df <- data.frame(Qtd=c(100,200,300,400,500),
op=c('V','C','C','V','V'), stringsAsFactors=F)
How can I turn the values in the Qtd column to negative if the value of the column op is V ??
I tried this command but it failed:
Teste <- within(df, Qtd[op == 'V'] <- -Qtd[])
Warning message:
In Qtd[op == "V"] <- -Qtd[] :
number of items to replace is not a multiple of replacement length