有没有办法让readr
将括号中的数字解析为负数?例如,在下面的代码中,我希望将列B
解析为数字,将第一项解析为-2.3。
library(readr)
data <- "A,B,C
1, (2.3), 4
2, 4.6, 7.1"
# B is parsed as chr
read_csv(data)
# B is parsed as a double, but (2.3) is interpreted as positive
read_csv(data, col_types = cols(B = col_number()))
目前我只是读作字符数据然后进行后处理,但我更愿意(比方说)注册一个自定义解析器。