How to use lapply and paste on multiple dataframes in a list

前端 未结 2 1899
Happy的楠姐
Happy的楠姐 2021-01-21 16:50

I can\'t combine the use of lapply and paste to combine two columns for multiple dataframes contained within a list. I\'ve looked through multiple sources, but can\'t find the a

2条回答
  •  情书的邮戳
    2021-01-21 16:54

    I think this is what you're going for:

    lapply(mylist, function(x) paste(x$Artist, x$Song, sep=" "))
    

    We just need to define the little anonymous function to concatenate the columns.

    [[1]]
    [1] "Drake Gods Plan"        "Ed Sheeran Perfect"     "Bruno Mars Finesse"    
    [4] "Camilla Cabello Havana" "BlocBoy Look Alive"    
    
    [[2]]
    [1] "Gucci Mane Black Beatles" "Migos Bad and Boujee"    
    [3] "Daft Punk Starboy"        "Chainsmokers Closer" 
    

提交回复
热议问题