0

在尝试使用超过最大整数 (.Machine$integer.max = 2147483647) 的列导入数据时遇到问题。使用 readr 的 read_csv 我相信它是作为 NA 导入的,而不是四舍五入。复杂性来自尝试使用 rbindlist 导入多个 csv。

这是我当前的设置:

 load_df_path <- file.path(".../dffolder") #path to folder
 df_path_files <- list.files <- (load_df_path, full.names = TRUE) #list files in path

 df <- rbindlist(lapply(df_path_files, read_csv)) # read in csvs using readr

如何编写最后一行以导入 csvs 并将列“数量”转换为字符而不是整数?

这是我尝试过的一些事情,但没有运气...

## This gets error: Error in switch(tools::file_ext(path)....
 df <- rbindlist(lapply(df_path_files, read_csv(df_path_files, col_types = list(amount = col_character())))) 


## recreate read_csv and changed col_types = NULL to the above but getting the warning
## Error in FUN(X[[i]], ...) : could not find function "read_delimited"

tl;dr - 需要帮助导入 csvs 列表,同时将特定列更改为字符格式或 int64。

谢谢你。

4

1 回答 1

1

你快到了,只是语法......

df_list <- lapply(df_path_files, read_csv, col_types = cols(amount = col_character()))
df <- rbindlist(df_list)

col_types期望NULL或创建的东西cols。见?read_csv?cols

另一个想法:也许强制执行numeric而不是int可能是一种解决方案:使用cols(amount = col_double()) 请参见此处: R 中的 long/bigint/decimal 等效数据类型

于 2017-01-12T09:20:57.010 回答