Quick question about subsetting via character-class

后端 未结 3 1503
情话喂你
情话喂你 2021-01-28 15:58

I think this is a super quick thing, but I figured I\'d ask since I can\'t for the life of me remember how to do it...

Suppose, I have a data.frame (call it, DF

相关标签:
3条回答
  • 2021-01-28 16:19

    DF$foo[1] tries to return the first element of the column named foo (which doesn't exist). You want DF[foo[1]].

    0 讨论(0)
  • 2021-01-28 16:39
    subset(DF, select=foo[3])
                  Blah
    1   0.814939149951
    2  -0.800644571486
    3  -0.424080059851
    4   1.012792429940
    5   1.291888735720
    6   0.642523425131
    7   0.537486547429
    8   0.315031122082
    9  -0.296439716108
    10  0.372453578695
    
    0 讨论(0)
  • 2021-01-28 16:43

    Is this what you want?

    DF[ ,foo][1]

    Ah, Joshua posted while I was typing... You can aslo select regions of the columns, eg:

    DF[1:3,foo][1]
    
    0 讨论(0)
提交回复
热议问题