subset - How to select columns based on criteria in a certain row in R -


i have matrix of values both row names , column names, shown here.

c5.outliers

days   j1      j2      j3      j4   0.01   458    -160    -151    -52      0.02   459    -163    -154    -46     0.03   457    -165    -150    -51    perc   0.99   0.04    0.00    0.52      

i create separate matrix using columns value row "perc" =<50.0. in example, extracting columns j2 , j3.

this code tried isn't working (the "perc" row row #1414 on matrix): c5.final<-subset(c5.outliers, 1414<.51)

i assume mean 0.50 since columns "perc" above 50.0.

this might not best way works:

#data: df <- data.frame(days=c(0.01,0.02,0.03,"perc"),j1=c(458,459,457,0.99), j2 =c(-165,-163,-160,0.04),j3=c(-151,-153,-131,0.00),j4=c(-52,-45,-51,0.52))  dfc <- subset(df,,select= which(c(true,(df[which(df$days == "perc"), ] <= 0.50)[2:5])))  dfc   days      j2   j3 1 0.01 -165.00 -151 2 0.02 -163.00 -153 3 0.03 -160.00 -131 4 perc    0.04    0 

you can remove true, if dont want df$days variable, change 0.50 threshold if needed , expand 2:5 if have columns or substitute "perc" 1414 if wish.

hope works.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -