Question: If I have a list of data frames 

```
my_list = list(data, data2, data3)

```

and I would like to add a column to each that is populated with that data frame's name

```
column1    column2    new_column    
12         27         data
27         987        data
378        1234       data

```

, how would I go about this? I would like all DFs within the set to retain their original names, but have it populate a column, as well.

I have tried:

```
my_list = lapply(my_list, function(DF){
     DF$new_column <- DF

     DF
})

```

but it doesn't run through the list within the function.

What am I missing? Thanks

Answer: 
Your list is unnamed. You can either make it named manually while creating it

```
my_list = list(data = data, data2 = data2, data3 = data3)

```

Or you can use `mget` & `ls` combination if you have many data sets

```
my_list <- mget(ls(pattern = "^data$|^data\\d+$"))

```

Afterwords, just use `Map`

```
my_list <- Map(cbind, my_list, new_clumn = names(my_list))
my_list
# $data
#   column1 column2 new_clumn
# 1      12      27      data
# 2      27     987      data
# 3     378    1234      data
# 
# $data2
#   column1 column2 new_clumn
# 1      12      27     data2
# 2      27     987     data2
# 3     378    1234     data2
# 
# $data3
#   column1 column2 new_clumn
# 1      12      27     data3
# 2      27     987     data3
# 3     378    1234     data3

#If you want to put the data sets back to the global environment you can use `list2env`
#list2env(my_list, .GlobalEnv) 
#Please Note that it is usually not the preffered practice to move data frames to the global environment and back. It is preferred to store all you data sets in list from the very beginning and manipulating them within the list using functions such as `Map`, `lapply`, etc.

```
I changed, now see if this is what you wanted:

```
names<-names(my_list)
count <- 0
lapply(my_list, function(DF){
    count <<- count+1
    DF[,length(DF)+1] <- names[count]
    names(DF)[length(DF)] <- "new_clumn"
    DF
})

```