On Sep 23, 2009, at 3:47 PM, Jim Silverton wrote:
> Hello,
> I have the following data:
>
> gene Actual groups reps
> 1 1 213 1 2
> 2 2 123 2 3
> 3 3 2 1 2
> 4 4 12 2 3
> 5 1 0 1 1
> 6 2 34 2 2
> 7 3 123 1 1
> 8 4 12 2 2
>
> I want to find the best way to store this so that it can be accessed
> quickly
> for other uses. Someone recommended an array as follows:
>
>
>
> actual_array=array(0,c(G,T,length(nj)))
> for (b in 1:length(gene)) {
> for (i in 1:max(gene)) {
> for (j in 1:max(groups)) {
> for (k in 1:max(reps)) {
> if ((gene[b]==i) && (groups[b]==j) &&
> (replicate[b]==k))
> {
> yijk_array[i,j,k]=yijk[b]
> }
> }
> }
> }
> }
>
>
> But this gives an array that has a lot of zeros in places where I
> don't have
> any data. Is there a way to overcome this and present a 'shortened'
> version?
The Matrix package has a sparse array construct that may ffer what you
seek.
--
David.
>
>
> Jim
>
> [[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.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT