I have a lot of tibbles similar to this one:
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"))
Here is the function I want to apply to all tibbles
EDIT following comment, I add x in my function as last line
MyCount <- function(x){
x$retweet <- NA
x$custom <- NA
x$retweet <- grepl(retw, x$text) * 1
x$custom <- (grepl(cust, x$text) & !grepl(retw, x$text)) * 1
x
}
I acces the tibbles this way:
myUser_tw <- ls(,pattern = "_tw")
as they all are the only ones in my env to end with _tw.
Now here is how I do to apply function:
for (i in 1:length(myUserList_tw)){
lapply(mget(myUserList_tw), MyCount)
}
but in fact it will not change anything. Running the following one df by one will change them the way I want. The printed result is OK.
lapply(mget(myUser_tw[x]), MyCount)
Now I can't find a way to assign the result to the df in my workspace. I have tried many things like this:
myUser_tw[x] <- lapply(mget(myUser_tw[x]), MyCount)
or include x <<- x
at the end of my function, but no success.
Cany anyone help me to save the modified df in my workspace? Thank you