[R] error: no such index at level 2

David Huffer David.Huffer at csosa.gov
Wed Jul 8 17:55:32 CEST 2009


Godmar, 

I don't follow...

  > q <- list ( )
  > q [[ 105 ]] <- as.numeric ( c ( 0 , 0 , 1 ) )
  > q [[ 104 ]] <- as.numeric ( c ( 1 , 1 , 1 ) )
  > q [[ 10 ]] <- as.integer ( c ( 3 , 3 , 1 ) )
  > crossRsorted <- data.frame ( i = c ( 105 , 104 , 10 ) )
  > q [ crossRsorted [ , 1 ] ]
  [[1]]
  [1] 0 0 1

  [[2]]
  [1] 1 1 1

  [[3]]
  [1] 3 3 1

  > length ( q [ crossRsorted [ , 1 ] ] )
  [1] 3
  >

How'd you come up with 

  > length(q)
  [1] 165
  > length(q[ crossRsorted[,1] ])
  [1] 15750

I must be missing something.  

--
 David
 
 -----------------------------------------------------
 David Huffer, Ph.D.               Senior Statistician
 CSOSA/Washington, DC           david.huffer at csosa.gov
 -----------------------------------------------------


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Godmar Back
Sent: Wednesday, July 08, 2009 9:58 AM
To: Henrique Dallazuanna
Cc: r-help at r-project.org; Petr PIKAL
Subject: Re: [R] error: no such index at level 2

On Wed, Jul 8, 2009 at 9:40 AM, Henrique Dallazuanna <wwwhsd at gmail.com>wrote:

> Its because '[[' accept only element, so you need use '[':
>
> q[crossRsorted[,1]]
>

This appears to be doing something different. For instance, my 'q' has 165
components, but what you suggest has 15750:
> length(q)
[1] 165
> length(q[ crossRsorted[,1] ])
[1] 15750

hardly what I want.

Meanwhile, it looks as though [[ ]] does not vectorize its arguments, it
curries them!

Note that:

> q[[c(105,104)]]
Error in q[[c(105, 104)]] : subscript out of bounds

gives the same error as:

> q[[105]][[104]]
Error in q[[105]][[104]] : subscript out of bounds

Very mysterious, though, in all fairness, explained in help("[[") where it
says:

     '[[' can be applied recursively to lists, so that if the single
     index 'i' is a vector of length 'p', 'alist[[i]]' is equivalent to
     'alist[[i1]]...[[ip]]' providing all but the final indexing
     results in a list.

which leads to square one: how to express "select all r[i] where q[[i]]
fulfills some predicate?"

 - Godmar

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Godmar Back
Sent: Wednesday, July 08, 2009 9:58 AM
To: Henrique Dallazuanna
Cc: r-help at r-project.org; Petr PIKAL
Subject: Re: [R] error: no such index at level 2

On Wed, Jul 8, 2009 at 9:40 AM, Henrique Dallazuanna <wwwhsd at gmail.com>wrote:

> Its because '[[' accept only element, so you need use '[':
>
> q[crossRsorted[,1]]
>

This appears to be doing something different. For instance, my 'q' has 165
components, but what you suggest has 15750:
> length(q)
[1] 165
> length(q[ crossRsorted[,1] ])
[1] 15750

hardly what I want.

Meanwhile, it looks as though [[ ]] does not vectorize its arguments, it
curries them!

Note that:

> q[[c(105,104)]]
Error in q[[c(105, 104)]] : subscript out of bounds

gives the same error as:

> q[[105]][[104]]
Error in q[[105]][[104]] : subscript out of bounds

Very mysterious, though, in all fairness, explained in help("[[") where it
says:

     '[[' can be applied recursively to lists, so that if the single
     index 'i' is a vector of length 'p', 'alist[[i]]' is equivalent to
     'alist[[i1]]...[[ip]]' providing all but the final indexing
     results in a list.

which leads to square one: how to express "select all r[i] where q[[i]]
fulfills some predicate?"

 - Godmar

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list