dataframe - Extracting a row from a data frame in R -


let's have matrix this:

> = matrix(  +   c(2, 4, 3, 1, 5, 7), # data elements  +   nrow=2,              # number of rows  +   ncol=3,              # number of columns  +   byrow = true)        # fill matrix rows   >                      # print matrix       [,1] [,2] [,3]  [1,]    2    4    3  [2,]    1    5    7 

now, used small example, imagine if matrix bigger, 200 rows , 5 columns etc. want do, minimum value column 3, , extract row. in other words, find , row 3rd attribute lowest in entire column of data frame.

datatoreturn <- which(a== min(a[, 3]) 

but doesn't work.

another way use which.min

a[which.min(a[, 3]), ] ##[1] 2 4 3 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -