csv 使用readr导入数据和设置列类型时出错

mwngjboj  于 2023-02-27  发布在  其他
关注(0)|答案(1)|浏览(123)

我正在导入一个csv文件,并试图设置一些数据类型的因素,如下图所示,这是猜测是字符最初。我认为这将有助于设置正确的数据类型时,导入,但我有麻烦的代码。

> ADT_v3 <- read.csv(("ADT.v3.csv"),
+ col_types = cols(
+     pat_enc_csn_id = col_double(),
+     pat_mrn_id = col_double(),
+     PAT_NAME = col_character(),
+     HOSP_ADMSN_TIME = col_time(format = ""),
+     HOSP_DISCH_TIME = col_time(format = ""),
+     ADT_datetime = col_time(format = ""),
+     ADT_event_name = col_factor(levels = c("Admission", "Transfer Out", "Transfer In", "Patient Update", "Census")),
+     location = col_character(),
+     ROOM_ID = col_double(),
+     level_of_care = col_factor(levels = c("NULL", "Floor", "ICU", "Floor with Tele", "Intermediate/Stepdown"))
+ ))
Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  unused argument (col_types = list(list(list(), list(), list(), list(""), list(""), list(""), list(c("Admission", "Transfer Out", "Transfer In", "Patient Update", "Census"), FALSE, FALSE), list(), list(), list(c("NULL", "Floor", "ICU", "Floor with Tele", "Intermediate/Stepdown"), FALSE, FALSE)), list(), NULL))

我试图确保代码没有错别字或错误,但......没有任何运气识别的问题。

72qzrwbm

72qzrwbm1#

试试这个:

ADT_v3 <- read_csv(("ADT.v3.csv"),
 col_types = cols(
     pat_enc_csn_id = col_double(),
     pat_mrn_id = col_double(),
     PAT_NAME = col_character(),
     HOSP_ADMSN_TIME = col_time(format = ""),
     HOSP_DISCH_TIME = col_time(format = ""),
     ADT_datetime = col_time(format = ""),
     ADT_event_name = col_factor(levels = c("Admission", "Transfer Out", "Transfer In", "Patient Update", "Census")),
     location = col_character(),
     ROOM_ID = col_double(),
     level_of_care = col_factor(levels = c("NULL", "Floor", "ICU", "Floor with Tele", "Intermediate/Stepdown"))
 ))

(only将read.csv替换为readr::read_csv

相关问题