[R] Two conditions selection

Rodrigo Díaz rodlupanow at hotmail.com
Tue Aug 4 22:50:01 CEST 2015


Hi. I have a matrix like this: 
cycle=c(rep(1,3),rep(2,3),rep(3,3),rep(4,3))col=c(rep("blue",2),rep("green",2),rep("blue",2),rep("green",2),rep("blue",2),rep("green",2))values=c(1:12)data.frame(cycle,col,values)
#  cycle   col values#1      1  blue      1#2      1  blue      2#3      1 green      3#4      2 green      4#5      2  blue      5#6      2  blue      6#7      3 green      7#8      3 green      8#9      3  blue      9#10     4  blue     10#11     4 green     11#12     4 green     12
I want to select or extract values matching 2 conditions. For example: values from col "blue" and cycle "1". If I use : values[col==blue] I get all blue values. I tried using values[c(col==blue,cycle==1)] but is not working. Please help. I have a very big data matrix and I do not wanna go to excel and start cutting the data. Thanks. 

 		 	   		  
	[[alternative HTML version deleted]]



More information about the R-help mailing list