I have a large number of species abundance samples taken at different depths. The data is arranged like:
df1 <- data.frame(sample = c('a', 'b', 'c', 'd', 'e','f','g','h','i'),
depth = c(10,20,30,10,20,30,10,20,30),
sp1 = c(1,0,0,2,0,0,5,0,0),
sp2 = c(1,4,6,5,3,1,5,6,4),
sp3 = c(0,0,0,0,2,0,0,0,0),
sp4 = c(1,0,5,4,3,7,8,4,1))
where the columns after sample and depth are indivdual species. I basically want to select only the species present in more than one depth and create a new dataframe looking at just these, like this:
df2 <- data.frame(sample = c('a', 'b', 'c', 'd', 'e','f','g','h','i'),
depth = c(10,20,30,10,20,30,10,20,30),
sp2 = c(1,4,6,5,3,1,5,6,4),
sp4 = c(1,0,5,4,3,7,8,4,1))
Any help would be much appreciated :)