Q:

Looping commands through a list of numbers in R

I am trying to create a loop for the following commands:
cluster0.markers <- FindMarkers(object=NF.combined, ident.1 = 0, min.pct = 0.25)
cluster1.markers <- FindMarkers(object=NF.combined, ident.1 = 1, min.pct = 0.25)
cluster2.markers <- FindMarkers(object=NF.combined, ident.1 = 2, min.pct = 0.25)

I have tried the following:
cluster.markers <- list(c(0:2))
cluster.markers[[1]] <- FindMarkers(object=NF.combined, ident.1 =i, min.pct = 0.25)

But this command gives only one object (cluster.markers), which includes results for cluster1.markers only. How can I modify this loop so I get three objects (cluster0.markers, cluster1.markers and cluster2.markers)?

A:

Using purrr: 
find_markers <- function(i) {
    FindMarkers(object=NF.combined, ident.1 = i, min.pct = 0.25)
}

cluster_markers <- 0:2 %>%
    map(~find_markers(.))

