I'm trying to add a word to the end of a string based on an ifelse statement and having trouble.
words <- c("one","two","one","four")
newword <- "word"
and then if the value equals "one", I want to append a word
words <- ifelse(words == "one",
gsub(paste(newword,sep = " "),"",words),
words)
I want the output to be
> words
[1] "one word" "two" "one word" "four"
any idea why I can't make this happen with an ifelse and the paste() function?
Thanks for the help!
Aucun commentaire:
Enregistrer un commentaire