R: add a new column to dataframes from a function

后端 未结 1 764
悲&欢浪女
悲&欢浪女 2021-01-23 08:36

I have many tibbles similar to this:

dftest_tw <- structure(list(text = c(\"RT @BitMEXdotcom: A new high: US$500M turnover in the last 24 hours, over 80% of i         


        
相关标签:
1条回答
  • 2021-01-23 09:15

    We can use tidyverse options. Get the value of multiple string objects with mget, then with map2 from purrr, create the new column 'Twitter.name in each dataset of the list with corresponding string element of 'myUserList`

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

    If we need to modify the objects in the global environment, use list2env

    list2env(lst, envir = .GlobalEnv)
    
    0 讨论(0)
提交回复
热议问题