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

Emmanuel Paradis paradis at isem.univ-montp2.fr
Wed May 24 14:53:45 CEST 2000


Dear all,

I am a bit surprised that R does not give a warning (or a message error)
when calling, in a data.frame (or a list), an element that does not exist:

> temp <- data.frame(my.var1 = c(1,2), my.var2 = c(3,4))
> temp
  my.var1 my.var2
1       1       3
2       2       4
> temp$my.var3                               ### it does not exist
NULL
> my.vect <- c(temp$my.var1, temp$my.var3)   ### no marning
> my.vect
[1] 1 2

I would expect a message saying that my.var3 is NULL when trying to
manipulate it. For instance, sum() gives:

> sum(temp$my.var3)
[1] 0

(the same with any suffix after $) which is again surprising since, to me,
the element does not exist.

Is there a reason for this?

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