[Rd] corrupt data frame: columns will be truncated or padded
with NAs in: format.data.frame(x, digits = digits)
Gregor GORJANC
gregor.gorjanc at bfro.uni-lj.si
Mon Feb 14 12:21:43 CET 2005
Hello!
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
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
> 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: http://www.bfro.uni-lj.si
Zootechnical Department mail: gregor.gorjanc <at> bfro.uni-lj.si
Groblje 3 tel: +386 (0)1 72 17 861
SI-1230 Domzale fax: +386 (0)1 72 17 888
Slovenia
More information about the R-devel
mailing list