无法根据colnames从CRAN_package_db()中对data.frame进行子集化

时间:2018-05-28 21:32:39

标签: r

我无法按名称从data.frametools::CRAN_package_db()进行子集化:

apkgs <- tools::CRAN_package_db()
apkgs[1, 65] # character vector of length one with an MD5sum

# But these don't work:
apkgs[1, "MD5sum"] # NA
apkgs[1, names(apkgs)[65]] # NA

## But these work, even though they're very similar?
mtcars[1, "mpg"]
mtcars[1, names(mtcars)[1]]

任何想法我做错了什么?

1 个答案:

答案 0 :(得分:2)

它不起作用,因为两列具有相同的名称(14和65)。

但你可以改用:

apkgs[1, which(names(apkgs) == "MD5sum")]