如何修复变量名称位于 R 中每一行的 CSV
How to fix a CSV where the variable names are in each row in R
文件的写法是变量名对应的值在同一行,如
"AD","ED","County","EDAD Status","Event","Party/Independent Body","Office/Position Title","District Key","VoteFor","Unit Name","Tally","65","001","New York","IN-PLAY","General Election 2021 - 11/02/2021",,"Mayor","NYC",1,"Public Counter",160
"AD","ED","County","EDAD Status","Event","Party/Independent Body","Office/Position Title","District Key","VoteFor","Unit Name","Tally","65","001","New York","IN-PLAY","General Election 2021 - 11/02/2021",,"Mayor","NYC",1,"Manually Counted Emergency",0
等等。
我们如何将其转换为 R 中的普通数据帧格式?
x <- read.csv("https://vote.nyc/sites/default/files/pdf/election_results/2021/20211102General%20Election/00000200000Citywide%20Mayor%20Citywide%20EDLevel.csv")%>%
select(-c(1:11))
colnames(x) <- c("AD","ED","County","EDAD Status","Event","Party/Independent Body","Office/Position Title","District Key","VoteFor","Unit Name","Tally")
文件的写法是变量名对应的值在同一行,如
"AD","ED","County","EDAD Status","Event","Party/Independent Body","Office/Position Title","District Key","VoteFor","Unit Name","Tally","65","001","New York","IN-PLAY","General Election 2021 - 11/02/2021",,"Mayor","NYC",1,"Public Counter",160 "AD","ED","County","EDAD Status","Event","Party/Independent Body","Office/Position Title","District Key","VoteFor","Unit Name","Tally","65","001","New York","IN-PLAY","General Election 2021 - 11/02/2021",,"Mayor","NYC",1,"Manually Counted Emergency",0
等等。
我们如何将其转换为 R 中的普通数据帧格式?
x <- read.csv("https://vote.nyc/sites/default/files/pdf/election_results/2021/20211102General%20Election/00000200000Citywide%20Mayor%20Citywide%20EDLevel.csv")%>%
select(-c(1:11))
colnames(x) <- c("AD","ED","County","EDAD Status","Event","Party/Independent Body","Office/Position Title","District Key","VoteFor","Unit Name","Tally")