问题
Possible Duplicate:
R: subset() logical-and operator for combining conditions should be & not &&
I have a simple question, but I don't know how to solve this... I want to select all rows where value_1 > 0 and value_2 > 0. Now I have this code:
dataOnBoth<-data[data$value_1 > 0,][data$value_2 > 0,]
When I head this data, ordering on log2_fold_change, I have This output:
gene_id sample_1 sample_2 status value_1 value_2 log2_fold_change
86 uc001aen.1 q1 q2 NOTEST 0.0619347 0 -1.79769e+308
150 uc001ahx.1 q1 q2 NOTEST 0.0432199 0 -1.79769e+308
186 uc001ajk.1 q1 q2 NOTEST 0.0854541 0 -1.79769e+308
251 uc001amf.1 q1 q2 NOTEST 0.0636211 0 -1.79769e+308
358 uc001are.3 q1 q2 NOTEST 0.3642040 0 -1.79769e+308
394 uc001ass.1 q1 q2 NOTEST 0.0196794 0 -1.79769e+308
test_stat p_value q_value significant
86 -1.79769e+308 0.4767020 1 no
150 -1.79769e+308 0.3960920 1 no
186 -1.79769e+308 0.0631033 1 no
251 -1.79769e+308 0.4428030 1 no
358 -1.79769e+308 0.1083640 1 no
394 -1.79769e+308 0.1489190 1 no
So R didn't test the second condition... When using the & to test both conditions, I receive 0 rows:
dataOnBoth<-data[data$value_1 > 0 && data$value_2 > 0,]
How do I select all rows where value_1 > 0 and value_2 > 0?
回答1:
You need to use a single '&':
dataOnBoth = data[data$value_1 > 0 & data$value_2 > 0,]
See this question for more details.
来源:https://stackoverflow.com/questions/13762402/r-multiple-conditions-in-row-selection-of-matrix