我想在data.frame中添加相同的字符串.
> df1 <- data.frame(pt1="a", pt2="b", row.names=1)
> df1
pt1 pt2
1 a b
Run Code Online (Sandbox Code Playgroud)
结果我希望:
pt1 pt2
1 Add this string a Add this string b
Run Code Online (Sandbox Code Playgroud)
我们可以用 lapply
df1[] <- lapply(df1, function(x) paste('Add this string', x))
Run Code Online (Sandbox Code Playgroud)
或者使用 Map
df1[] <- Map(paste, 'Add this string', df1)
Run Code Online (Sandbox Code Playgroud)
要么
library(dplyr)
df1 %>%
mutate_each(funs(paste('Add this string', .)))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1628 次 |
| 最近记录: |