I've this data.frame. And i need to loop through every column and search for "SI", then change it for the columns name.
I have this:
SKU Tv.y.Video Cómputo Tecnología
2003091090002P NO NO NO
2003091090002 NO NO NO
2003120060006P NO NO NO
2003120060006P NO NO NO
2003120060006 NO NO NO
2004121460000P NO SI NO
2004121460000 NO SI NO
2004121440002P NO SI NO
2004121440002 NO SI NO
2004123030003P NO SI NO
Need to get this:
SKU Tv.y.Video Cómputo Tecnología
2003091090002P NO NO NO
2003091090002 NO NO NO
2003120060006P NO NO NO
2003120060006P NO NO NO
2003120060006 NO NO NO
2004121460000P NO Cómputo NO
2004121460000 NO Cómputo NO
2004121440002P NO Cómputo NO
2004121440002 NO Cómputo NO
2004123030003P NO Cómputo NO
My code:
I've tried this with this code:
df$Tv.y.Video <- mutate(df$Tv.y.Video,
Tv.y.Video = ifelse(sub("SI", Tv.y.Video), "Tv.y.Video", Tv.y.Video))
But got this message:
Error in UseMethod("mutate_") :
no applicable method for 'mutate_' applied to an object of class "factor"
So i've change the class of that column to character with this:
df$Tv.y.Video <- as.character(df$Tv.y.Video)
And got this message:
Error in UseMethod("mutate_") :
no applicable method for 'mutate_' applied to an object of class "character"
This is the result from str(df):
'data.frame': 10 obs. of 4 variables:
$ SKU : Factor w/ 9028 levels "2003014460004",..: 9 8 16 16 15 842 841 840 839 846
$ Tv.y.Video: chr "NO" "NO" "NO" "NO" ...
$ Cómputo : Factor w/ 2 levels "NO","SI": 1 1 1 1 1 2 2 2 2 2
$ Tecnología: Factor w/ 2 levels "NO","SI": 1 1 1 1 1 1 1 1 1 1