lundi 9 avril 2018

r - ifelse with multiple columns (apply)

I am new to understanding the apply world and while i am starting to understand the concept, have trouble with the application.

i have multiple columns with "Y" in as a value that I would like to change to the last letter of the column name.

I would like to use the following to get a the list of columns to apply the function to:

flaggs2015 <- grep("Flag", names(ItemStats_2015))

here is an example of what i would like to do with 1 column:

ItemStats_2015$Item_Flag_A <- ifelse(ItemStats_2015$Item_Flag_A == "Y", str_sub(flaggs2015[1], -1, -1), NA)

except i would, obviously, like to do it over any column with 'Flag' in the name at the same time.

Aucun commentaire:

Enregistrer un commentaire