I am stuck on a question for an assignment for a base R class.
I need to use if()
to change the names of several objects. Anything named af, aflb, afub, afwb, or afws will be changed to af_type. They are in the column LANDSCAPE.
Here is the code I have tried:
poppy <- read.csv("~/baseR-V2021.1EXP/data/exercise_dat/bearclawpoppy.csv")
af_type <- if(any(poppy$LANDSCAPE == "af", "aflb", "afub", "afwb", "afws"))"af_type"
af_type <- if(any(poppy$LANDSCAPE == "af", "aflb", "afub", "afwb", "afws")){"af_type"}
When these didn't work, I tried to simplify it:
af_type <- if(poppy$LANDSCAPE == "af")"af_type"
I get an error saying argument is of length zero.
Then I tried:
af_type <- ifelse(poppy$LANDFORM == "af", "af_type", "other")
Return labelled all objects "other".
Here is a screenshot to show what the dataset looks like.
I would appreciate advice! Thank you
question from:
https://stackoverflow.com/questions/65912614/change-object-names-using-if 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…