简体   繁体   中英

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:

[[10]]
             x
1   115.065808
2    97.358465
3    92.434613
4   146.454943

How can I do it?

Thanks

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:

set.seed(1234)
your_list <- list(data.frame(a=1:10), data.frame(a=rnorm(50)), data.frame(b=letters[1:10]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM