[R] Inserting Missing Data

Peter Langfelder peter.langfelder at gmail.com
Wed Nov 10 22:57:16 CET 2010


On Wed, Nov 10, 2010 at 1:38 PM,  <Kurt_Helf at nps.gov> wrote:
>
> Greetings
>     I'm attempting to insert missing data on the smallest size class of
> cave cricket instars into a data frame. The data involve censusing
> photoplots (plots) of roosting cave crickets in which we discern in four
> instars or size classes.  I need to insert data on size class one into a
> data frame that already has data on size classes two through four.  The
> data can be merged by their cave name, year, month, region (near or far
> from cave entrance), plot #, and Individual (IndID).  For example:
> (Embedded image moved to file: pic14606.jpg)
>
> As one example, I have data for size class (SC) one I can insert after
> IndID #4 in the data above.  However, when I attempt to merge these two
> data frames using the following commands:
> "Hs.full.anal<-merge(Hs.short.missgval,SC1_0608,
>      byx=c(Cave,Year,Month,Region,Plot,IndID),
>      byy=c(Cave,Year,Month,Region,Plot,IndID))"
> I get the following message:
> "WARNING: Warning in `[<-.factor`(`*tmp*`, ri, value = c(1L, 1L, 1L, 1L,
> 1L, 1L, 1L,  :
>  invalid factor level, NAs generated"

Hard to say with the level of detail you provided, but chances are
that your data are converted (internally) to factors. If not too
inconvenient, I would quit the R session without saving anything,
restart and type

options(stringsAsFactors=FALSE)

before running anything. This prevents storing of character vectors as
factors. If you already have a data frame that stores factors, you can
try something along the lines of

newFrame = apply(frame, 2, as.character)

Hope this helps,

Peter



More information about the R-help mailing list