[R] no warning with NULL component in data.frame

Emmanuel Paradis paradis at isem.univ-montp2.fr
Wed May 31 18:07:46 CEST 2000


Dear all,

I sent a message a few days ago about NULL components in list or
data.frame. To reiterate, if I have a list or a data.frame, and try to
manipulate some elements using the $ symbol, no warning is given if the
elements do not exist.

	> DF <- data.frame(x=c(1,2), y=c(3,4))
	> DF
	  x y
	1 1 3
	2 2 4
	> tmp <- c(DF$u, DF$v)
	> tmp
	NULL

Practically, I met the problem recently reading some data with:

	DF <- read.table(..., header=TRUE)

where the column names were L1, L3, L4, L5, L6 (L2 missing), and then went
on concatenating all these:

	X <- c(DF$L1, DF$L2, DF$L3, DF$L4, DF$L5, DF$L6)

which, of course, gave no warning, but then I realized that the length of X
was not what I expected.

A work-around to this particular problem would be to attach the data.frame:

	> attach(DF)
	> tmp <- c(u, v)
	Error: Object "u" not found

But yet, I do not understand the reason for this:

	> DF$anything.you.could.imagine
	NULL

since I would expect something like:

	> DF$anything.you.could.imagine
	Error: Component "anything.you.could.imagine" not found in Object "DF"

I suppose this has more to do with the design of the language. I understand
too that components within lists or data frames are not objects. 

Best,

Emmanuel Paradis
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list