Re: [Rd] corrupt data frame: columns will be truncated or padded with NAs in:, digits = digits)

From: Gregor GORJANC <>
Date: Mon 14 Feb 2005 - 22:21:43 EST


Prof Brian Ripley wrote:
> You did create a corrupt data frame by using *replacement* on part of
> something that did not exist. The simple workaround is not to do that.
> One can argue about what should happen in such a case and currently R
> assumes that you know what you are doing and will only treat the data
> frame as a list. We could make this an error, but that would add an
> overhead to be paid by careful users too.
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
  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:, 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

> If you really want to understand what is going on here, please read the
> source code: R is a volunteer project and the volunteers do not have
> time to explain each and every one of your error messages to you -- we
> have already had several goes over including data frames in data frames.
I try to and I hope I did not take to much of your time.

[... removed the rest ...]

Lep pozdrav / With regards,
     Gregor GORJANC

University of Ljubljana
Biotechnical Faculty       URI:
Zootechnical Department    mail: gregor.gorjanc <at>
Groblje 3                  tel: +386 (0)1 72 17 861
SI-1230 Domzale            fax: +386 (0)1 72 17 888

______________________________________________ mailing list
Received on Mon Feb 14 21:45:27 2005

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:02:52 EST