2017-01-12 31 views
0

在嘗試導入超過最大整數(.Machine $ integer.max = 2147483647)的列的數據時遇到我的代碼問題。使用readr的read_csv我相信它是作爲NA導入而不是四捨五入。複雜性來自於試圖用rbindlist導入多個csvs。綁定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 

我怎樣寫的最後一行導入CSV並在轉列「量」字符,而不是整數?

這裏有幾件事情我想沒有任何運氣...

## 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;博士 - 需要幫助導入CSV中的列表,同時改變特定列字符格式或一個Int64。

謝謝。

回答

1

你是幾乎沒有,只是語法...

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

col_types預計到cols創建NULL什麼的。請參閱?read_csv?cols

另外一個想法:也許執行numeric代替int可能是一個解決辦法:使用cols(amount = col_double()) 在這裏看到: long/bigint/decimal equivalent datatype in R

+0

謝謝你的語法修復!我會看看使用數字! – ant