[R] adding zeros to dataframe

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


Greetings,
 
I am new to R and am hoping to get some tips from experienced R-programmers.
 
I 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.
 
My programming skills are still somewhat rudimentary (and biased toward VBA-style looping...which seems to be leading me astray). Though I have searched, I have not yet seen this particular problem addressed in the help files.
 
Many thanks for any suggestions,
Cathy
 
<mailto:ccollins at ku.edu> 
  




More information about the R-help mailing list