[R] summarizing matrix data

2008-03-02 Thread Emilio Gagliardi
Hi everyone,

I'm sure this is simple, but I can't seem to figure this out.

Situation.  3 different groups of subjects each submit n X n matrices of
scores.  What I want to do is aggregate each group of scores into a summary
n X n matrix.  I need the result to be a matrix so that I can calculate a
dissimilarity structure on it.  So I thought I would create a
multi-dimensional array and store the data that way.

The first two dimensions represent the data, the third the group membership
(say 3 groups), and forth represents subjects(30 subjects per group)...

subject.data - array(NA, dim=c(3,3,3,10))

data.1 - matrix(seq(from=1,to=9,by=1),nrow=3,ncol=3)
data.2 - matrix(seq(from=11,to=19,by=1),nrow=3,ncol=3)
data.3 - matrix(seq(from=21,to=29,by=1),nrow=3,ncol=3)
data.4 - matrix(seq(from=31,to=39,by=1),nrow=3,ncol=3)
data.5 - matrix(seq(from=41,to=49,by=1),nrow=3,ncol=3)
data.6 - matrix(seq(from=51,to=59,by=1),nrow=3,ncol=3)

subject.data[,,1,1] - data.1   # subject 1 group 1
subject.data[,,2,1] - data.2   # subject 1 group 2
subject.data[,,3,1] - data.3   # subject 1 group 3
subject.data[,,3,2] - data.4   # subject 2 group 3
subject.data[,,2,2] - data.5   # subject 2 group 2
subject.data[,,1,2] - data.6   # subject 2 group 1

what I want is conceptually:
array.group1 - apply(subject.data[,,1,],mean)
array.group2 - apply(subject.data[,,2,],mean)
array.group3 - apply(subject.data[,,3,],mean)

each of the summary matrices then contain the mean for each cell across all
subjects within a group so that it has the same size as the subject data.
Also, after I've populated subject.data, there will be segments that will
only contain NAs, how do you grab just the portions of the array that
contain data? I know the function is.na() will get me an index I just don't
know how to write it correctly.  something like
only.data - subject.data[!is.na(subject.data)]

Does that make?  I would appreciate any help regarding a better way to store
the data and obviously how to get back these summary matrices...

Thanks very much for your help.

emilio

[[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.


Re: [R] summarizing matrix data

2008-03-02 Thread Emilio Gagliardi
Henrique,

Again, thank you very much for your code snippets, I am learning from them,
but they are also creating as many questions as answers...

On Sun, Mar 2, 2008 at 11:48 AM, Henrique Dallazuanna [EMAIL PROTECTED]
wrote:

 Then you can try this:

 apply(array(as.vector(sapply(patt, get)), dim = c(dim(get(patt[1])),
 ngroups, nsubs)), 1:3, mean)


 For create the matrices in a loop one option is:

 lapply(seq(1, 51, by=10), function(x)matrix(seq(x, x+8), nrow=3, ncol=3))


if I use the above code, I get back a list of matrices, which is awesome!
The problem is that your code to get the means doesn't work on it (
apply(array(as.vector(...))...additionally, I'm not creating the data, but
reading it in, file by file and I don't know what group to assign a file
until I open it (group2, group4, group4,group1,group3,group2,group1,etc)

so I have 120 files to open and process and each file can be assigned to 1
of 4 groups(or lists as your code demonstrates)...but I don't know until I
open the file which group hence my loop and meta structure approach.  So I
need to open the file, create a matrix from it (which I have working), store
it along with other data from the same group, and then after I've read all
the files and associated the data with a group, then I can generate the
means per cell.

So I can create 4 lists of matrices, which is fine by me but I don't see how
I extend your code snippets to the case of reading the data from files...I
currently have 1 master matrix which holds all the subject data as I
mentioned in my previous post.
data[3,3,1,nsubjects] represents all the subject data in group 1
data[3,3,2,nsubjects] represents all the subject data in group 2
data[3,3,3,nsubjects] represents all the subject data in group 3

how do i pullout just one group's worth of data and apply the mean function
to each cell ?
group1 - get(data[,,1,] ?
group2 - get(data[,,2,] ?
mean1 - apply(group1,1:3,mean) # mean per cell, so nine means (3 x 3) for
each group...
mean2 - apply(group2,1:3,mean) # mean per cell, so nine means (3 x 3) for
each group...

thanks so much for your patience!
emilio

[[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.


[R] install problem 2.6 mac os x 10.5

2007-11-03 Thread Emilio Gagliardi
Hi everyone,

I am trying to install R-2.6 over my 2.5.1 installation on Mac OS X  
10.5.

R version 2.5.1 (2007-06-27)

I double-click the installer package,
1) Click Continue
2) Click Continue
3) Click Continue + Click Agree

On the Installation Type dialog screen, all four options are grayed  
out, with skip beside them.  The Install button is also grayed out.   
If I click the Standard Install button, it allows me to change the  
directory to install onto, but then brings me back to the same screen.

So I can't install.  If I click any one the four options [R Framework,  
R GUI, etc] the message says There is a more recent version of this  
software installed on your system.  There is no need to install this  
older version.

What am I missing here?

Thanks for your help.

__
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.