Skip to content
Prev 15172 / 63421 Next

corrupt data frame: columns will be truncated or padded with NAs in: format.data.frame(x, digits = digits)

Hello!
Prof Brian Ripley wrote:
I agree to some extent, however I was very surprised of this behaviour. I 
often deal with data that have missing values and now I really do not know 
how to manage such data. How can one add a column to existing data frame
in such a way, that you don't get corrupted data frames as in my example?

(tmp <- data.frame(y1=1:4, f1=factor(c("A", "B", "C", "D"))))
   y1 f1
1  1  A
2  2  B
3  3  C
4  4  D
# Add new column, which is not full (missing some data for last
# records)
tmp[1:2, "y2"] <- 2
tmp
  y1 f1   y2
1  1  A    2
2  2  B    2
3  3  C <NA>
4  4  D <NA>
Warning message:
corrupt data frame: columns will be truncated or padded with NAs
in: format.data.frame(x, digits = digits)

I hope that this is not the best solution:
tmp <- data.frame(y1=1:4, f1=factor(c("A", "B", "C", "D")))
tmp$y2 <- NA
tmp[1:2, "y2"] <- 2
tmp
I try to and I hope I did not take to much of your time.

[... removed the rest ...]