Strange behaviour dropping column from data.frame in R

后端 未结 4 1370
逝去的感伤
逝去的感伤 2020-12-18 15:52

I\'ve encountered a strange behavior when dropping columns from data.frame. Initially I have:

> a <- data.frame(\"a\" = c(1,2,3), \"abc\" = c(3,2,1));          


        
4条回答
  •  没有蜡笔的小新
    2020-12-18 16:31

    From the R Language Definition [section 3.4.1 pg.16-17] --

    https://cran.r-project.org/doc/manuals/r-release/R-lang.pdf

    Character: The strings in i are matched against the names attribute of x and the resulting integers are used. For [[ and $ partial matching is used if exact matching fails, so x$aa will match x$aabb if x does not contain a component named "aa" and "aabb" is the only name which has prefix "aa". For [[, partial matching can be controlled via the exact argument which defaults to NA indicating that partial matching is allowed, but should result in a warning when it occurs. Setting exact to TRUE prevents partial matching from occurring, a FALSE value allows it and does not issue any warnings. Note that [ always requires an exactmatch. The string "" is treated specially: it indicates ‘no name’ and matches no element (not even those without a name). Note that partial matching is only used when extracting and not when replacing.

提交回复
热议问题