Dear Cathy,
Try this:

# Some data
set.seed(123)
DF <- data.frame(
       Plot=sample(10),
       Location = sample(10),
       SpeciesName = sample(LETTERS[1:10]),
       SpeciesNumber = sample(10),
       abundance = rnorm(10),
       treatment = sample(letters[1:3],5, replace=TRUE)
       )

# Making some NAs in Plot
DF[c(2,7,10),1] <- NA
DF

# Hopefully what you asked for :-)
DF$abundance[is.na(DF$Plot)] <- 0
DF    # note than rows 2, 7 and 10 in abundance are now zero

See ?is.na for details.

HTH,

Jorge



On Fri, May 1, 2009 at 1:20 PM, Collins, Cathy <ccollins@ku.edu> wrote:

> 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@ku.edu>
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]


