我有很多类似的小问题:
dftest_tw <- structure(list(text = c("RT @BitMEXdotcom: A new high: US$500M turnover in the last 24 hours, over 80% of it on $XBTUSD. Congrats to the team and thank you to our u…",
"RT @Crowd_indicator: Thank you for this nice video, @Nicholas_Merten",
"RT @Crowd_indicator: Review of #Cindicator by DataDash: t.co/D0da3u5y3V"
), Tweet.id = c("896858423521837057", "896858275689398272", "896858135314538497"
), created.date = structure(c(17391, 17391, 17391), class = "Date"),
created.week = c(33, 33, 33)), .Names = c("text", "Tweet.id",
"created.date", "created.week"), row.names = c(NA, -3L), class = c("tbl_df",
"tbl", "data.frame"))
为了测试,我们添加另一个:
dftest2_tw <- dftest_tw
我有我的 df 列表:
myUserList <- ls(,pattern = "_tw")
我想做的是:
1-添加一个名为的新列Twitter.name
2-用 df name填充列,所有这些都在一个函数中。以下代码适用于一一采取的每个 df:
dftest_tw %>% rowwise() %>% mutate(Twitter.name = myUserList[1])
期望的结果是这样的:
MyRes <- structure(list(text = c("RT @BitMEXdotcom: A new high: US$500M turnover in the last 24 hours, over 80% of it on $XBTUSD. Congrats to the team and thank you to our u…",
"RT @Crowd_indicator: Thank you for this nice video, @Nicholas_Merten",
"RT @Crowd_indicator: Review of #Cindicator by DataDash: t.co/D0da3u5y3V"
), Tweet.id = c("896858423521837057", "896858275689398272", "896858135314538497"
), created.date = structure(c(17391, 17391, 17391), class = "Date"),
created.week = c(33, 33, 33), retweet = c(0, 0, 0), custom = c(0,
0, 0), Twitter.name = c("dftest_tw", "dftest_tw", "dftest_tw"
)), .Names = c("text", "Tweet.id", "created.date", "created.week",
"retweet", "custom", "Twitter.name"), class = c("rowwise_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -3L))
当要编写一个函数以应用于我所有的 df(超过 100 个)时,我无法实现它。任何帮助,将不胜感激。