Skip to content
Prev 179028 / 398503 Next

adding zeros to dataframe

On 01-May-09 17:20:08, Collins, Cathy wrote:
Suppose we call your dataframe "abun.df". Then its columns will be
something like abun.df$location, abun.df$name, abun.df$abundance,
abun.df$trtmt (depending on what you called them in the first place).
a species was not recorded have no value entered. In that case,
presumably they have gone into abun.df$abundance as "NA". You can
check this with a command like

  sum(is.na(abun.df$abundance))

If you get a positive result, then that is likely to be the case.
As a cross-check:

  sum(abun.df$abundance > 0, na.rm=TRUE)

should give another number which, together with the first, should
add up to the total number of rows in the dataframe.

Assuming, then, that this is the case, the simplest method to set
the non-recorded values to 0 is on the lines of

  ix <- (is.na(abun.df$abundance))
  abun.df$abundance[ix] <- 0

Then you can run the check

  sum(abun.df$abundance == 0)

and you should get a number which is the same as you got from

  sum(is.na(abun.df$abundance))

Hoping this helps,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 01-May-09                                       Time: 18:39:58
------------------------------ XFMail ------------------------------