Hi:

The : operator is meant for numeric sequences; see ?':'

On Tue, Jan 19, 2010 at 7:57 PM, rusers.sh <rusers...@gmail.com> wrote:

> Hi,
>  I know we can use 1:10 to represent the 1,2,3,...,10 numbers, but the
> following conditions are except.
>  Anybody knows how to represent the following two cases with similar usage
> of ":"  or others? Usually, i will get several hundred names for them, such
> as a1,a2,... or f[[1]],f[[2]],...
> #Example data
> a1<-array(1:12,c(2,3,2)); a2<-array(2,c(2,3,2)); a3<-array(0,c(2,3,2))
> a1[1,2,1]:a3[1,2,1]
> [1] 3 2 1 0
> #the correct result should be 3,2,0
>

I tried this:

> a <- list(a1, a2, a3)
> unlist(lapply(a, '[', 1, 2, 1))
[1] 3 2 0

 If you're trying to get the same element out of a bunch of arrays, this
might be one way to go.
You might also want to investigate the iapply function in the iterators
package, since it manipulates
indices in 3D arrays rather easily.

HTH,
Dennis


 So the method  of using "a1[i,j,k]:a3[i,j,k]" to represent
> "c(a1[i,j,k],a2[i,j,k],a3[i,j,k])" is not correct?
> ##For lists with matrices as its elements
> f<-list()
> f[[1]]<-a1;f[[2]]<-a2;f[[3]]<-a3
> f[[1]][1,2,1]:f[[3]][1,2,1]
> [1] 3 2 1 0
> #the correct result should be 3,2,0
>   So the method  of using "f[[1]][i,j,k]:f[[3]][i,j,k]" to represent
> "f[[1]][i,j,k],f[[2]][i,j,k],f[[3]][i,j,k])" is not correct?
>  I noticed that the above two methods have got the same results, although
> not correct. So i guess i have made the same errors in them. Is there some
> method to represent them concisely?
>  Any ideas about them?
>  Thanks a lot.
>
>
> --
> -----------------
> Jane Chang
> Queen's
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to