Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I want to append to a data.frame the same string.
> df1 <- data.frame(pt1="a", pt2="b", row.names=1) > df1 pt1 pt2 1 a b
As a result I would like to have:
pt1 pt2 1 Add this string a Add this string b
We can use lapply
lapply
df1[] <- lapply(df1, function(x) paste('Add this string', x))
Or use Map
Map
df1[] <- Map(paste, 'Add this string', df1)
Or
library(dplyr) df1 %>% mutate_each(funs(paste('Add this string', .)))
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.