I was importing a csv file and trying to set some data types to factor as seen below, which were guessed to be character originally. I figure it would be helpful to set the correct data type when importing but am having trouble with the code.
> 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))
I've tried to make sure the code doesn't have typos or errors but....haven't had any luck identifying the problem.
Try this:
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 replaced read.csv
by readr::read_csv
)