4

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

1 Answer 1

7

We can use lapply

df1[] <- lapply(df1, function(x) paste('Add this string', x))

Or use Map

df1[] <- Map(paste, 'Add this string', df1)

Or

library(dplyr)
df1 %>%
     mutate_each(funs(paste('Add this string', .)))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.