g'day all,

 

I need help with this please. 

I have a dataset of site names and years they were trapped in (a subset of
it is bs, below) and a dataset of sites that actually caught animals
(subsetted as brep, below). I need to add to brep, a row with a zero in the
classcount column, for every year each site was trapped but caught nothing.

 

so for Site 1, I need to add rows that say "Site1 Reptilia 0 2005", "Site1
Reptilia 0 2007", "Site1 Reptilia 0 2008" etc to 2010.

 

 

years trapped (bs) 

(the data column is when they were trapped (so not in 2010 for Site1),
sequence is the range of years (2004:2010) repeated)

 

   site  data sequence

1  Site1 2004     2004

2  Site1 2005     2005

3  Site1 2006     2006

4  Site1 2007     2007

5  Site1 2008     2008

6  Site1 2009     2009

7  Site1      0       2010

8  Site2 2004     2004

9  Site2 2005     2005

10 Site2 2006     2006

11 Site2    0        2007

12 Site2 2008     2008

13 Site2    0        2009

14 Site2    0     2010

 

sites with captures (brep)

 

   site    class classcount year

6  Site1 Reptilia          3 2004

7  Site1 Reptilia          1 2006

11 Site2 Reptilia          7 2005

12 Site2 Reptilia          4 2006

13 Site2 Reptilia          4 2008

 

 

I have got it to work, slightly (below) but the range of bs is longer than
the range of brep so it only does it twice (in this case)

 

x<-range(bs$sequence)

added<-c()

for (i in 1:(x[2]-x[1]+1)) {

 
ifelse(brep$year[i]==bs$data[i],print("blah"),added<-cbind(as.character(brep
$site[i]),as.character(brep$class[i]),0,bs$sequence[i]))

  added

}

 

 

any advice would be greatly appreciated

many thanks

 

James

 

James Smith

Wildlife Ecologist, Mornington Sanctuary

Australian Wildlife Conservancy

+61 8 9191 7014

 


	[[alternative HTML version deleted]]

