user6644063 user6644063 - 1 year ago 100
R Question

Convert data.frames within a list into numeric vectors

I have got 10 data.frames, each one with only one column, contained within a list and I have to convert them into numeric vectors.

Here an example of my 10th data.frame within the list:

1 115.065808
2 97.358465
3 92.434613
4 146.454943

How can I do it?


lmo lmo
Answer Source

Here are two ways to convert a list of data.frames, each with one column to a list of unnamed vectors.

1) Using unlist

your_new_list <- lapply(your_list, unlist, use.names = FALSE)

2) Using the extraction operator, [[

your_new_list <- lapply(your_list, "[[", 1)

Here's a sample list to try it out:

your_list <- list(data.frame(a=1:10), data.frame(a=rnorm(50)), data.frame(b=letters[1:10]))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download