[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 13:32:04 CET 2005


Sending this also to r-help so anyone can read it also there and maybe also 
help me with my puzzle if this trivial and I don't see it.

Prof Brian Ripley wrote:
[... removed some ...]
> You add a column, not replace part of a non-existent column.  Isn't that 
> obvious, given what you wrote?

# OK. If I do
tmp <- data.frame(y1=1:4, f1=factor(c("A", "B", "C", "D")))
tmp[1:2, "y2"] <- 2
# I am changing nonexistent column y2 in data frame tmp.

# If I do
tmp <- data.frame(y1=1:4, f1=factor(c("A", "B", "C", "D")))
tmp$y2 <- NA
tmp[1:2, "y2"] <- 2
# I am changing existent column. I understand now the difference. However,
# it is weird for me that this is OK (if column y2 does not yet exist)
tmp["y2"] <- 2
# but this is not
tmp[1:2, "y2"] <- 2

> There is a lot of basic documentation on data manipulation in R/S, and a 
> whole chapter in MASS4.  Somehow most other people don't seem to find 
> this a problem.

I just ordered MASS4 last week and I am eager to get it in my hands. In 
meanwhile I read quite some documentation and what I more or less saw is

tmp <- data.frame(y1=1:4, f1=factor(c("A", "B", "C", "D")))
tmp$y2 <- 1:4
tmp$y3 <- 2*tmp$y1

i.e. everybody is adding full column to data frame. But I would like to add 
just one part.

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

More information about the R-devel mailing list