在尝试导入列超过最大整数(.Machine$integer.max = 2147483647)的数据时,代码出现问题。使用readr的read_csv,我相信它是作为NA导入的,而不是舍入。复杂性来自于尝试使用rbindlist导入多个csvs。
这是我当前的设置:
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,并将"amount“列转换为字符而不是整数?
这里有几个我尝试过但没有任何运气的事情。
## 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 -在将特定列更改为字符格式或int64时,需要帮助导入csvs列表。
谢谢。
发布于 2017-01-12 17:20:57
你就快到了,只是语法...
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())请看这里:long/bigint/decimal equivalent datatype in R
https://stackoverflow.com/questions/41608553
复制相似问题