[R] error

Petr Savicky savicky at cs.cas.cz
Wed Feb 15 14:36:16 CET 2012


On Wed, Feb 15, 2012 at 02:13:28PM +0100, Soheila Khodakarim wrote:
> Dear All,
> I have a function that it works in all of data.
> 
> dim(data)
> 24(sample)   2600(variable)
> data
> 
> 
>           [1]        [2]         [3]       [4]  ...   [2600]
> 
> [1] 10.73140 9.89450 9.12233 8.33994 9.43412 [2] 10.58010 10.02023 8.69257
> 8.46640 9.05038 [3] 10.80644 9.59991 8.71311 8.64168 9.08396 [4] 10.85874
> 9.16161 9.27786 9.10818 9.70617 [5] 10.89607 10.02847 8.81274 8.77573
> 9.12501
> 
> ...
> [24]  10.71652   9.71979     9.23088   8.87465   9.49099
> 
> Now I want that the function works on 100 subgroups of data.
> 
> I determined this subgroups by subgroup matrix
> 
> dim(subgroup)
> 
> 100(subgroup)  2600(variable)
> 
> Subgroup
> 
>          [1]     [2]      [3]    [4]... [2600]
> [1]       1      0         0       0         0
> [2]       1      0         0       0         0
> [3]       1      0         0       0         0
> [4]       0      1         0       0         0
> [5]       0      0         1       0         0
> ...
> [100]     0      0         1       0         0
> 
> 
> 
> the elements of subgroup are 1 ( show us the variable belongs the subgroup)
> or 0 (show us the variable does not belong the subgroup)
> 
> 
> 
> result <- apply(subgroup , 1, function(z) func_LL(data[which(z==1),]))
> 
> but I saw this error
> 
> Error in ncol(data) : subscript out of bounds
> while our dimensions are correct, I think:(

Hi.

The vector z is a row of matrix subgroup, so its length
is the number of columns in data. So, i think, you mean

  result <- apply(subgroup , 1, function(z) func_LL(data[, which(z==1)]))

where which(z==1) selects columns, not rows of data.

Hope this helps.

Petr Savicky.



More information about the R-help mailing list