I need help in subseting a dataframe:
data1<-data.frame(year=c(2001,2002,2003,2004,2001,2002,2003,2004, 2001,2002,2003,2004,2001,2002,2003,2004), firm=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4),x=c(11,22,-32,25,-26,47,85,98, 101,14,87,56,12,43,67,54), y=c(110,220,302,250,260,470,850,980,1010,140,870,560,120,430,670,540)) data1 I want to keep the firms where all x>0 (where there are no negative values in x) So my output should be: year firm x y 1 2001 3 101 1010 2 2002 3 14 140 3 2003 3 87 870 4 2004 3 56 560 5 2001 4 12 120 6 2002 4 43 430 7 2003 4 67 670 8 2004 4 54 540 So I'm doing: data2<-data1[data1$firm%in%subset(data1,data1$x>0),] data2 But the result is [1] year firm x y <0 rows> (or 0-length row.names) Thank you for any help CecĂlia Carmo (Universidade de Aveiro) [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.