我的问题如何使用read_csv只读取某些列BY NAME。例如:
tmp <- read_csv("outcome-of-care-measures.csv")
dim(tmp)
[1] 4706 46
names(tmp)[c(11,17,23)]
[1] "Hospital 30-Day Death (Mortality) Rates from Heart Attack"
[2] "Hospital 30-Day Death (Mortality) Rates from Heart Failure"
[3] "Hospital 30-Day Death (Mortality) Rates from Pneumonia"
如果我想使用read_csv并使用col_only()选项,我怎么能一次只读取其中一列。
我唯一想到的就是:
tt <- read_csv("outcome-of-care-measures.csv", col_types = cols_only(Hospital 30-Day Death (Mortality) Rates from Heart Attack=col_character()), n_max = 10)
Error: unexpected numeric constant in "tt <- read_csv("outcome-of-care-measures.csv", col_types = cols_only(Hospital 30
我有一个坚定的预感我的问题是使用names()给出的列的名称,需要一些指导。
尝试在我的书中遵循这个例子:
logdates <- read_csv("data/2016-07-20.csv.gz", col_types = cols_only(date = col_date()), n_max = 10)
答案 0 :(得分:1)
基本上我可以告诉我使用的名称应该以不同的方式输入。每个塞巴斯蒂安-c的建议反传都有效。