简体   繁体   中英

How to extract numbers from numeric object

For example, for numbers 412,34523,123412 I would extract 4,3 and 1. I guess I can turn them into characters, sliced them and then pick the first. Is there any better way?

Try:

s=c(412,34523,123412)
 substring(s,1,1)
[1] "4" "3" "1"

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