Skip to content

index to select rows of a large matrix

4 messages · tsunhin wong, jim holtman

#
Dear R Users,

I have created a 1500 x 20000 data frame - DataSeq. Each of the 1500
rows represents a data sequence.
I have another data frame iData that stores the information of these
1500 data sequences in the same order, for example, condition, gender,
etc.

If I use "subset" to select certain groups within iData according to
some criteria that I have set, e.g. condition, gender
Then how can I used the retrieved subset of iData to point to and
retrieve corresponding rows in the DataSeq data.frame for
manipulations and analysis?

I hope some of you can give me some idea!
Thank you very much!!!

- John
#
Dear Jim,
Thanks for your suggestion.

I have a follow-up question for fellow R Users that have followed this thread:

*I used to create two lists by some very flexible criteria to compare
from "iData" and pass the two lists to *ANOTHER FUNCTION* that further
decompose the two lists and do some case by case analysis:

comp.lst[[1]] <- subset(iData,(Session==1 & TrialList==2 & BadTrial==0
& Correct==1 & Critical.BT>0))
comp.lst[[2]] <- subset(iData,(Session==2 & TrialList==2 & BadTrial==0
& Correct==1 & Critical.BT>0))

*The function will then do some subject by subject processing:

tmplist <- comp.lst[[1]]
subject <- unique(tmplist$Subject)
Psubjmatrix <- NULL
for(j in 1:length(subj)) { ##divide the list and process per subject in the list
        subjtriallist <- subset(tmplist,(Subject==subj[j])) ##divide
the list and process per subject in the list
        print(paste("Start working on Subject ",subj[j],sep=""),quote=FALSE)
        ##The sub-divided list is passed to another function to
extract data from corresponding object
        Ptrialmatrix <- SeekObject(subjtriallist,seconds,samplesize,sdmax);
        ##add rowmean to subject pupil matrix
        Psubjmatrix <- cbind(Psubjmatrix, rowMeans(Ptrialmatrix,
na.rm=TRUE, dims=1))
}

*But now, I have a pre-processed the objects and cooked up a
1500x20000 matrix, and there is no need to get these objects one by
one for extraction, I may just do the following:

Ptrialmatrix <- PMasterMatrix[subjindex,,drop=FALSE]

*However, on passing the index to the function, I cannot further
sub-divide the list index by Subject.

I have been thinking of passing the criteria to within the function.
But... what smarter thing I can do to make it works?

- John
On Thu, May 21, 2009 at 10:33 AM, jim holtman <jholtman at gmail.com> wrote:
#
Dear all,

I found the answer:
intersect()

- John
On Thu, May 21, 2009 at 7:32 PM, tsunhin wong <thjwong at gmail.com> wrote: