Strange behaviour dropping column from data.frame in R

后端 未结 4 1368
逝去的感伤
逝去的感伤 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:55

    From the the help. ?$

    name: A literal character string or a name (possibly backtick quoted). For extraction, this is normally (see under ‘Environments’) partially matched to the names of the object.

    So that's the normal behaviour because the name is partially matched. See ?pmatch for more info about partial matching.

    Cheers

提交回复
热议问题