[R] conditional filter resulting in 2 new dataframes

andrewjt atrant at mun.ca
Sun Aug 14 03:02:21 CEST 2011


This is what I am starting with:

initial<- matrix(c(1,5,4,8,4,4,8,6,4,2,7,5,4,5,3,2,4,6), nrow=6,
ncol=3,dimnames=list(c("1900","1901","1902","1903","1904","1905"),
c("sample1","sample2","sample3")))

And I need to apply a filter (in this case, any value <5) to give me one
dataframe with only the 'less than 5' values and with '0' place holders on
the values that don't meet this criteria. The second dataframe is the same
but for those values >=5.

Should look like this:
less <- matrix(c(1,0,4,0,4,4,0,0,4,2,0,0,4,0,3,2,4,0), nrow=6,
ncol=3,dimnames=list(c("1900","1901","1902","1903","1904","1905"),
c("sample1","sample2","sample3")))
more <- matrix(c(0,5,0,8,0,0,8,6,0,0,7,5,0,5,0,0,0,6), nrow=6,
ncol=3,dimnames=list(c("1900","1901","1902","1903","1904","1905"),
c("sample1","sample2","sample3")))

Any ideas? 



--
View this message in context: http://r.789695.n4.nabble.com/conditional-filter-resulting-in-2-new-dataframes-tp3742232p3742232.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list