[R] "subscript out of range" message

Jason Turner jasont at indigoindustrial.co.nz
Fri Aug 22 05:29:30 CEST 2003


arinbasu at softhome.net wrote:
> Hi All:
> I was recently working with a dataset on arsenic poisoning. Among the 
> variables in the dataset, I used the following three variables to 
> produce crosstabulations (variable names: FOLSTAT, GENDER, ASBIN; all 
> three were categorical variables, FOLSTAT denoted follow up status for 
> the subjects and had seven levels, GENDER denoted sex (two levels: 
> male,female), and ASBIN denoted binarized arsenic concentrations (two 
> levels: "<0.05", ">0.05" denoting less than 0.05 mg/L and more than 0.05 
> mg/L respectively).
> To illustrate, I used the following code for crosstabulation:
> x <- table(FOLSTAT,GENDER,ASBIN)
> # from the results, I then wanted to subset a table for the ASBIN
> value ">0.05"
> I used the following code to subset the table:
> y <- x[,,ASBIN=">0.05"]

Two errors.

1) Your logical index won't work.  For the second level of ASBIN, use 
x[,,2].  Since the third dimension of the table x has only 2 elements 
(one for each level of ASBIN), sending it a logical vector that is as 
long as your number of subjects (N) is only going to confuse it.  It's 
going to run out of levels of table.  And it did - "subscript out of ..."

1) Is this a cut-and-paste error?
 > y <- x[,,ASBIN=">0.05"]
It won't work anyway, but for future reference, logical "equals" is ==, 
not =.  In other words, "==" is a question, "=" is an assignment.

Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
64-21-343-545
jasont at indigoindustrial.co.nz




More information about the R-help mailing list