R and approximate match in the column's name

后端 未结 1 1638
春和景丽
春和景丽 2020-12-19 20:26

I notice that sometimes R uses approximate match when I manipulate a column.

Example

age=18:19
height=c(76.1,77)
village=data.frame(age=age,height=he         


        
相关标签:
1条回答
  • 2020-12-19 21:01

    You can use [

    > village["ag"]
    Fehler in `[.data.frame`(village, "ag") : undefined columns selected
    
    > village["age"]
      age
    1  18
    2  19
    

    The function [[ allows both approaches (argument exact):

    > village[["ag"]]
    NULL
    
    > village[["age"]]
    [1] 18 19
    
    > village[["ag", exact = FALSE]]
    [1] 18 19
    

    The phenomenon is called partial matching (see ?pmatch):

    > pmatch("ag", names(village))
    [1] 1
    
    0 讨论(0)
提交回复
热议问题