From ripley at stats.ox.ac.uk  Mon Feb 14 12:38:22 2005
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon Feb 14 12:38: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: <421089C7.8080401@bfro.uni-lj.si>
References: <7FFEE688B57D7346BC6241C55900E730B6FF14@pollux.bfro.uni-lj.si>
	<Pine.LNX.4.61.0502140725570.22249@gannet.stats>
	<421089C7.8080401@bfro.uni-lj.si>
Message-ID: <Pine.LNX.4.61.0502141127480.5184@gannet.stats>

On Mon, 14 Feb 2005, Gregor GORJANC wrote:

> 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?

You add a column, not replace part of a non-existent column.  Isn't that 
obvious, given what you wrote?

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.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


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