I have a data.table called md that looks like this
group_1 group_2
a a
b a
b b
c c
I use the following code:
groups <- c("group_1","group_2")
for (group in groups)
{
md[!get(group)=="a",get(group):="b"]
md[,get(group):=factor(x = get(group),levels = c("a","b"),ordered = T)]
}
So I want for both columns in the data.table if the value for every row is not "a" then replace the value with "b" and then add ordered levels to it.
But I get an error Error in get(group): object 'group_1' not found
Any ideas ?
get(group) :=should be justgroup :=group, whereas i want to replace the values at the existing columns(group) :=