【发布时间】:2020-05-26 07:18:41
【问题描述】:
我已将来自 Coursera 网站的数据解析为列。我有 6 列,它们的长度都不同,但我需要正确映射它们以形成数据框。我不能用来自rowr 包的cbind.fill() 做到这一点。我不能用简单的cbind.data.frame() 或data.table()(来自data.table 包)来做到这一点。
这是示例代码。
c1 <- c("one", "two", "three", "four")
c2 <- c("55k", "98m", 340k")
c3 <- c("Toronto University", "NYU", "Yale", "Harvard")
c4 <- c("Beginner", "Intermediate")
data <- rowr::cbind.fill(c1, c2, c3, c4, fill = NA) # does not match the vars
data <- cbind.data.frame(c1, c2, c3, c4) # does not match the vars, either
data <- data.table(c1, c2, c3, c4) # the same situation
我需要像这样收到 df:
c1 c2 c3 c4
one 55k Toronto University Beginner
two 98m NYU Intermediate
three 349k Yale NA
four NA Harvard NA
【问题讨论】:
标签: r dataframe vector mapping match