[R] rbind to array members

Tony Plate tplate at acm.org
Mon Oct 19 21:10:49 CEST 2009


Unfortunately, I can't read your examples.  Can you repost without the formatting characters which are confusing when rendered in plain text?

One thing to keep in mind is that a R array is a regular object -- e.g., if you have a 2 x 3 x 4 array, then if you want to add a row to a slice, you must add a row to all the slices.   When I read "to add a row in place to a single table of the 3 dimensional array" it sounds like you might be trying to do something that's not possible with R arrays. However, if I could see your examples, then I probably give more help.

-- Tony Plate

Another Oneforyou wrote:
>  <4ADBCA02.8020101 at temple.edu>
> Content-Type: text/plain; charset="Windows-1252"
> Content-Transfer-Encoding: quoted-printable
> MIME-Version: 1.0
> 
> 
>> =20
>> library(abind)  ## array binding
> 
> I've looked into using abind()=2C but it seems I might not understand it pr=
> operly.
> 
> I can build my 2 table array=2C and insert a row into each table using:
> 
> =A0=A0=A0=A0=A0=A0=A0 x <- array(0=2Cc(1=2C3=2C2))
> 
> =A0=A0=A0=A0=A0=A0=A0 x[=2C=2C1] <- c(1=2C2=2C3)
> 
> =A0=A0=A0=A0=A0=A0=A0 x[=2C=2C2] <- c(7=2C8=2C9)
> 
> 
> And I can use rbind() or abind() to add a row to the first table and assign=
>  it to a separate object.
> 
> =A0=A0=A0=A0=A0=A0=A0 y <- rbind(x[=2C=2C1]=2C c(4=2C5=2C6))
> 
> =A0=A0=A0=A0=A0=A0=A0 z <- abind(x[=2C=2C1]=2C c(4=2C5=2C6)=2Calong=3D0)
> 
> 
> But I can't determine how to add a row in place to a single table of the 3 =
> dimensional array. For example=2C this does not work:
> 
> =A0=A0=A0=A0=A0=A0=A0 x[=2C=2C1] <- abind(x[=2C=2C1]=2C c(4=2C5=2C6)=2Calon=
> g=3D0)
> 
> Error in x[=2C =2C 1] <- abind(x[=2C =2C 1]=2C c(4=2C 5=2C 6)=2C along =3D =
> 0) :=20
> =A0 number of items to replace is not a multiple of replacement length
> 
> 
> I would like 'x' to be:
> 
>> x
> 
> =2C =2C 1
> 
> =A0=A0=A0=A0 [=2C1] [=2C2] [=2C3]
> 
> [1=2C]=A0=A0=A0 1=A0=A0=A0 2=A0=A0=A0 3
> 
> [2=2C]=A0=A0=A0 4=A0=A0=A0 5=A0=A0=A0 6
> 
> =2C =2C 2
> 
> =A0=A0=A0=A0 [=2C1] [=2C2] [=2C3]
> 
> [1=2C]=A0=A0=A0 7=A0=A0=A0 8=A0=A0=A0 9
> 
> 
> 
> 
> Thanks for any help.
>  		 	   		 =20
> _________________________________________________________________
> Hotmail: Trusted email with Microsoft=92s powerful SPAM protection.
> 
> ______________________________________________
> 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