[R] inserting into data frame gives "invalid factor level, NAs generated"

karinlag at ifi.uio.no karinlag at ifi.uio.no
Wed Aug 12 17:49:33 CEST 2009

I am calculating some values that I am inserting into a data frame. From
what I have read, creating the dataframe ahead of time is more efficient,
since rbind (so far the only solution I have found to appending to a data
frame) is not very fast.

What I am doing is the following:

# create data frame

goframe = data.frame(goA = character(10), goB = character(10), value =
goframe[1,] = c("AA", "BB", 0.4)

Result is:

> goframe[1,] = c("AA", "BB", 0.4)
Warning messages:
1: In `[<-.factor`(`*tmp*`, iseq, value = "AA") :
  invalid factor level, NAs generated
2: In `[<-.factor`(`*tmp*`, iseq, value = "BB") :
  invalid factor level, NAs generated

Is there another/better/more recomended way of doing this? If not, how do
I do this without getting all the warnings?



Karin Lagesen

More information about the R-help mailing list