Delete a column in a data frame within a list

后端 未结 4 1387
小鲜肉
小鲜肉 2020-12-03 03:44

I made a list out of my dataframe, based on the factor levels in column A. In the list I would like to remove that column. My head is saying lapply, but not anything else :P

4条回答
  •  一生所求
    2020-12-03 04:12

    If you are tidyverse user there is an alternative solution, which utilizes map function from purrr package.

    # Create same sample data as above
    myList <- list(A = data.frame(ID = c("A", "A"), 
                                  Test = c(1, 1), 
                                  Value = 1:2), 
                   B = data.frame(ID = c("B", "B", "B"), 
                                  Test = c(1, 3, 5), 
                                  Value = 1:3))
    # Remove column by name in each element of the list
    map(myList, ~ (.x %>% select(-ID)))
    

提交回复
热议问题