简体   繁体   中英

How could I extract all the numbers from a data frame into a vector?

Now I have a table of number which may have duplicated ones and NA. I want to extract all the numbers into a single vector and remove all the NA

How should I do that?

Now I'm considering doing it column by column, (gt1 is my table and FGT is the first column)

as.numeric(unlist(str_extract_all(gt1$FGT, "\\d")))

I want to get c(35, 20, 28... However, the result of it is that it extracts all the digits, which is c(3, 5, 2, 0, 2, 8, ...

Extract all the elements with

x = unlist(gt1,use.names=FALSE)

Making them numeric with

x = as.numeric(x)

Now you may remove NAs and duplicates via

x = x[!is.na(x)]
x = unique(x)

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