Return row of Data Frame based on value in a column - R

后端 未结 4 1000
無奈伤痛
無奈伤痛 2021-01-31 09:43

My R data.frame df looks like:

     Name     Amount
1    \"A\"      150
2    \"B\"      120
3    \"C\"      \"NA\"
4    \"D\"      160
.
.
.
         


        
4条回答
  •  执笔经年
    2021-01-31 10:21

    Use which.min:

    df <- data.frame(Name=c('A','B','C','D'), Amount=c(150,120,175,160))
    df[which.min(df$Amount),]
    
    > df[which.min(df$Amount),]
      Name Amount
    2    B    120
    

    From the help docs:

    Determines the location, i.e., index of the (first) minimum or maximum of a numeric (or logical) vector.

提交回复
热议问题