【发布时间】:2018-06-18 21:16:31
【问题描述】:
我正在尝试读取 CSV 文件 - 并且正在尝试强制列为某种类型。但是最后一列给了我一个错误:“is.list(col_types) 中的错误:未知快捷方式:g”
有什么建议吗?谢谢!
library(readr)
# Create data frame & write it out:
temp <- data.frame(a = 1:1001,
mystring_b = c(rep(NA, 1000), "1"),
mystring_c = c(rep(NA, 1000), "2"))
write.csv(temp, "temp.csv", row.names = F)
# Grab its names:
temp_labels <- names(read_csv("temp.csv", n_max = 0))
# Specify data type - for each column:
labels_type <- ifelse(grepl("mystring", temp_labels), "numeric", "guess")
# Reading in while forcing column types:
temp <- read_csv("temp.csv", col_types = labels_type)
# Error in is.list(col_types) : Unknown shortcut: g
【问题讨论】:
-
您传递给
col_types参数的内容似乎与文档所说的预期不符。您是否检查过文档以验证您是如何指定列类型的?