Reputation: 794
I have a list with names of 30 columns in a dataframe.
I have to apply replace to these 30 columns only. I tried:
list = names(df[!,r"Com"]) - ok!
Then I am trying:
replace!(df[!,list],"RR" =>"AA") - Fail
How can I do such transformation(with certain columns at once)?
Upvotes: 1
Views: 432
Reputation: 69949
There are several ways to do it. In what I write below I assume you want to update the df
data frame in-place (i.e. you do not want a new data frame, but change the existing one).
foreach(col -> replace!(col, "RR" => "AA"), eachcol(df[!, r"Com"]))
or
mapcols!(col -> replace!(col, "RR" => "AA"), df[!, r"Com"])
or
transform!(df, Cols(r"Com") .=> col -> replace!(col, "RR" => "AA"), renamecols=false)
Upvotes: 1