Skip to content

indexing by empty string (was RE: Error in predict.randomForest ... subscript out of bounds with NULL name in X)

2 messages · Ista Zahn, Liaw, Andy

#
Hi Andy,
On Tuesday, January 31, 2012 08:44:13 AM Liaw, Andy wrote:
You can index them by number, e.g.,
junk[, 2]

and you can use which() to find the numbers where the colname is empty.

junk[, which(colnames(junk) == "")]
Going back to the original issue with predict, I don't think you need a 
workaround. I think you need give your matrix some colnames.

Best,
Ista
#
Hi Ista,

When you write a package, you have to anticipate what users will throw at the code.  I can insist that users only input matriices where none of the column names are empty, but that's not what I wish to impose on the users.  I can add the name if it's empty, but as a user I don't want a function to do that, either.  That's why I need to look for a workaround.

Using which() seems rather clumsy for the purpose, as I need to combine those with the non-empty ones, and preserving ordering would be a mess.

Andy
Notice:  This e-mail message, together with any attachme...{{dropped:11}}