[R] Can I write Nothing to a variable?
Carl Witthoft
carl at witthoft.com
Wed Oct 28 22:22:52 CET 2009
Just wondering if it's possible to have an item with no content at all.
Here's what I was hoping to do, inside a larger function that acts on
a 3-D array.
I want to enter, as one of the arguments to the main function, the index
over which I'm going to do some action. For example, if the action were
to calc a sum, I'd specify a given axis and report the sums along that
axis for all coordinate pairs on the other two axes of the array.
So, I'd hoped to define three variables sort of like
A1 = 'i'
A2 = 'j'
A3 = {nothing}
then a loop over i and j around a command something like (not the real
code, but you get the idea):
> sum(thearray[get(A1),get(A2),get(A3)])
which in my optimistic mind would turn into "sum(thearray[i,j,])"
. The problem is that I don't see any way to have nothing whatsoever
in the selected index. A value of A3='' gets interpreted as a 'blank'
name or some such.
I solved the problem by setting the value to
A3 = 'seq(1,dim(thearray)[3])' (or similar),
but just would like to know in general if there is some way to put
nothing at all in there. (NA and NULL don't work)
Carl
More information about the R-help
mailing list