From gregor.gorjanc at bfro.uni-lj.si  Mon Feb 14 13:32:04 2005
From: gregor.gorjanc at bfro.uni-lj.si (Gregor GORJANC)
Date: Mon Feb 14 13:32:31 2005
Subject: [Rd] corrupt data frame: columns will be truncated or padded
	with NAs in: format.data.frame(x, digits = digits)
In-Reply-To: <Pine.LNX.4.61.0502141127480.5184@gannet.stats>
References: <7FFEE688B57D7346BC6241C55900E730B6FF14@pollux.bfro.uni-lj.si>
	<Pine.LNX.4.61.0502140725570.22249@gannet.stats>
	<421089C7.8080401@bfro.uni-lj.si>
	<Pine.LNX.4.61.0502141127480.5184@gannet.stats>
Message-ID: <42109A44.4050701@bfro.uni-lj.si>

Hello!

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
tmp
# 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
tmp
# 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
Slovenia


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