Search code examples
rdplyrplyr

Alternative to dlply in R or dplyr


I'm trying to remove dependency on plyr and have a line which uses the dlply function.

translation <- dlply(data ,.(key), function(s) key = as.list(s))

I've tried to use lapply and split based on a previous answer but cannot work out how to translate the key and as.list parts.


Solution

  • If we want to get similar structure, use split and then unclass

    lapply(split(data, data$key), unclass)
    

    -testing

    lapply(split(head(mtcars), head(mtcars)$cyl), unclass)