How to access single elements in a table in R

后端 未结 3 654
梦谈多话
梦谈多话 2020-12-23 20:52

How do I grab elements from a table in R.

My Data looks like this:

         V1     V2
1      12.448 13.919
2      22.242  4.606
3           


        
3条回答
  •  渐次进展
    2020-12-23 21:19

    That is so basic that I am wondering what book you are using to study? Try

    data[1, "V1"]  # row first, quoted column name second, and case does matter
    

    Further note: Terminology in discussing R can be crucial and sometimes tricky. Using the term "table" to refer to that structure leaves open the possibility that it was either a 'table'-classed, or a 'matrix'-classed, or a 'data.frame'-classed object. The answer above would succeed with any of them, while @BenBolker's suggestion below would only succeed with a 'data.frame'-classed object.

    I am unrepentant in my phrasing despite the recent downvote. There is a ton of free introductory material for beginners in R: https://cran.r-project.org/other-docs.html

提交回复
热议问题