R:从函数内部的字节中删除列

时间:2017-09-01 15:22:41

标签: r dataframe dplyr

这是this topic的后续内容。这是我的3个小组:

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"))
dftest1_tw <- dftest_tw
dftest2_tw <- dftest_tw
myUserList <- ls(,pattern = "_tw")

在昨天的主题之后,我在运行时得到了想要的结果:

library(tidyverse) 
lst <- mget(myUserList) %>% 
          map2(myUserList,  ~mutate(.data = .x, Twitter.name = .y)) %>%
list2env(lst, envir = .GlobalEnv)

我需要为每个df删除几列。这可以在一个df上运行时完成:

select_(dftest_tw, quote(-text), quote(-Tweet.id), quote(-created.date))

在将代码应用于列表的每个成员时,似乎有一个严重的问题。在使用lapply或编写函数时,我无法找到将其应用于所有df的方法:

MySelect <- function(x){
  select_(x, quote(-text), quote(-Tweet.id), quote(-created.date))
  x
}
for(var in myUserList){MySelect(get(var))}

感谢您的帮助。

0 个答案:

没有答案