I have a dataframe, where I extract a certain subset:
tmp <- mtcars |> select(disp, hp)
then I make some data manipulation
tmp$disp <- tmp$disp*0
tmp$hp <- tmp$hp*2
Now I want to reintegrate the changes into the original How?
Of course I could work on the original df in the first place but I just want to know how to replace all values from a df by a subset.
I want to keep the order of the column names and if possible I don't want to use any index. I also assume there are use cases where the select query is long.
answer is:
mtcars <- mutate(mtcars, tmp)
edit: add this solution, which could be more intuitive
newdf <- mtcars |> mutate(tmp)