[R] Apologies: example of data needing zeros-no NA values

Collins, Cathy ccollins at ku.edu
Fri May 1 19:59:19 CEST 2009


 
Many thanks for your responses.  I realize I made the first-time-poster's error of not giving an example of the data.  There actually are no NA values, so I'm not simply replacing values in the data frame. So, the number of species (and therefore abundance values) listed in each treatment differs, even though they all have the same number of plots sampled.
 
Sample_ID	 Spec_num	 Species_ID	 Abundance	 Treatment	
1	 1	   SOLCAN	 0.05	 1	
2	 1	   SOLCAN	 1.5	 1	
3	 1	   SOLCAN	 2.1	 2	
4	 1	   SOLCAN	 3.2	 2	
5	 2	   ERISTR	 2.4	 1	
6	 2	   ERISTR	 3.1	 1	
7	 2	   ERISTR	 5.6	 1	
8	 2	   ERISTR	 6.3	 1	
9	 2	   ERISTR	 2	 1	
10	 2	   ERISTR	 3	 2	
11	   2  	ERISTR	 2.1	 2	
 
 
Sorry for the repeat posting.
 
cathy
 
ORIGINAL MESSAGE:   have a dataset that I've read into R as a dataframe. There are 5 columns: Plot location,species name, a species number code (unique to each species name), abundance, and treatment. There are 272 plots in each treatment, but only the plots in which the species was recorded have an abundance value.  For all species in the dataset, I would like to add zeros to the abundance column for any plots in which the species was not recorded, so that each species has 272 rows.  The data are sorted by species and then abundance, so all of the zeros can presumably just be tacked on to the last (272-occupied plots) row for each species.




More information about the R-help mailing list