简体   繁体   中英

R cast string to raw?

How do I convert from "character" to "raw" ?

class ( plot_binary  )
# [1] "raw"
plot_binary[3]
# [1] 4e
class ( plot_binary[3] ) 
# [1] "raw"

I want to do a conversion from a character "4e" to a raw 4e .

How do I do this?

as.raw obviously not work because

as.raw("4e")
# [1] 04

Found a solution:

as.raw ( as.hexmode ( "4e" ) )
#[1] 4e

尝试查看: rawToCharcharToRaw

R accepts hexadecimal numeric input prefixed with 0x .

> as.raw(0x4e)
[1] 4e

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