0

This is a followthrough of this topic. Here are my 3 tibbles:

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")

Following yesterday topic, I have the wanted result when running this:

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

I need to drop a few columns for each df. This do the job when running on one df:

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

It seems like I have a serious probelm when it comes to apply code to each member of a list. I can't find a way to apply it to all df when using lapply, or writing a function:

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

Thank you for your help.

gabx
  • 472
  • 2
  • 7
  • 18
  • 1
    remove `x` at the end of function, it returns the original data frame instead of the data frame with dropped columns. – Psidom Sep 01 '17 at 15:44
  • @Psidom running for(var in myUserList){MySelect(get(var))} does not print error, but my df are still the same. – gabx Sep 01 '17 at 16:22
  • Your function doesn't modify data frame in place. Try `lapply`, `lapply(mget(myUserList), function(df) MySelect(df))` which gives you a new list of data frames. – Psidom Sep 01 '17 at 17:08

0 Answers0