Skip to content

Problem subsetting: undefined columns

6 messages · Aurélien PHILIPPOT, Paul Hiemstra, jim holtman +1 more

#
On 12/02/2011 07:20 AM, Aur?lien PHILIPPOT wrote:
Hi Aurelien,

I would call this a feature, not a bug. I think R does what it should
do, you request a non-existent column and it throws an error. What kind
of behavior are you looking for instead of this error?

regards,
Paul

  
    
#
?try

If you know that you might have a problem with undefined columns, or whatever, then trap the error with 'try' so your program can recover.  You could also validate the data that you are going to use before entering the loop; standard defensive programming - errors are always going to happen, so guard against them.

Sent from my iPad
On Dec 2, 2011, at 2:20, Aur?lien PHILIPPOT <aurelien.philippot at gmail.com> wrote:

            
How about this?

d[, v[v %in% colnames(d)]]

Michael
On Dec 2, 2011, at 12:01 PM, Aur?lien PHILIPPOT <aurelien.philippot at gmail.com> wrote: