Hello Data Wranglers,
Lets consider the dataset as below:
df <- data.frame( AA = runif(10), AB = runif(10), AC = runif(10),
BA = runif(10), BB = runif(10), BC = runif(10),
top1 = c("AA","AB","AA","AA","AA","AA","AA","AA","AA","AC"),
top2 = c("BA","BC","AC","BB","AB","AB","BA","BB","AC","AB"),#"AC.4)","AC.8)","AC.7)"),
top3 = c("BB","AA","BA","BA","BC","BA","BB","BA","BA","AB")#AB(.4)","AB(.8)","AA(.7)")
)
Expected output would be additional 6 columns (datatype logical)
df <- data.frame( AA = runif(10), AB = runif(10), AC = runif(10),
BA = runif(10), BB = runif(10), BC = runif(10),
top1 = c("AA","AB","AA","AA","AA","AA","AA","AA","AA","AC"),
top2 = c("BA","BC","AC","BB","AB","AB","BA","BB","AC","AB"),
top3 = c("BB","AA","BA","BA","BC","BA","BB","BA","BA","AB"),
isAA = True if column name "AA" is present in any of the columns starting with "top" i.e top1,top2,top3 else False
isAB = True if column name "AB" is present in any of the columns starting with "top" i.e top1,top2,top3 else False
........
isBC = True if column name "BC" is present in any of the columns starting with "top" i.e top1,top2,top3 else False
)
How can we use mutate_at in this case, not sure how to use the mutate_at to look at few columns only. **Especially how can we compare this row wise
I tried this but doesn't produce expected result because it doesnt check row wise and based on column name
mylist1 <- colnames(df)
df$isAA <- ifelse(df$top1 %in% mylist,T,F)
Even small hint would help, Champ