[R] variable (column) in a data frame

Paulo Barata paulo.barata at ensp.fiocruz.br
Sun Jul 15 18:38:48 CEST 2012


Dr. Dalgaard,

Thank you. You are right, with() is able to catch
spelling errors in the name of variables inside a data frame.

But couldn't some error or warning be included in R when referring
to a non-existent variable inside a data frame with the df$var
notation, without the use of with()? 

Is there any reason why R does not have such a kind of error
message?

Thank you again.

Paulo Barata

---------------------------------------------------------------------


---------- Original Message -----------
From: peter dalgaard <pdalgd at gmail.com>
To: "Paulo Barata" <paulo.barata at ensp.fiocruz.br>
Cc: r-help at r-project.org
Sent: Sun, 15 Jul 2012 18:14:22 +0200
Subject: Re: [R] variable (column) in a data frame

> On Jul 15, 2012, at 17:41 , Paulo Barata wrote:
> 
> > 
> > Dr. Dalgaard,
> > 
> > Thank you. But pre-checking with is.null() or using with()
> > doesn't solve the problem of catching spelling mistakes
> > in the name of a variable inside a data frame, when using 
> > the df$var notation often in a program.
> > 
> > Is there some way for R to behave, in relation to a variable 
> > inside a data frame, the same way it behaves for a variable 
> > not in a data frame? For example:
> 
> You could try reading the 2nd half of my one-line reply....
> 
> >> 
> >> You can pre-check for is.null(df$aaa) or use with(df, sum(aaa==2)).
> 
> -- 
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
> 
> -- 
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
------- End of Original Message -------



More information about the R-help mailing list