Each row of my dataframe has these data items: Stuff1 Stuff2 TripID StopID moreStuff1 moreStuff2 ...
I might have 2 entries for TripID=9011890 and StopID=Reseda, while I know the "Universe" for that combination was 7. I'd like to set a new variable (Call it X1) with a value of 3.5 for the two entries with TripID=9011890 and StopID=Reseda. It gets messy when I have 0 entries for a combination. My "expanded" TripID/StopID X1 values don't add to the total for the TripID. If I sum "X1" for TripID=9011890 I'll get only say 23 when the sum of the targets was 34. I want to have another variable (call it X2) with a value 34/23. I've started by making a .csv file that's a "table" with each row listing a TripID and each column a StopID. I cannot combine the .csv file data with the dataframe data. Even though I'm using the same commands for each, I get different "data structure" results. My current script is as follows: #### SurveyData <- read.spss( {Snip} ) NewTargetData <- read.table( {Snip} ) # CurrentX1Sums <- as.matrix(xtabs(~TripID+StopID, data=SurveyData)) CurrentX2Sums <- apply(CurrentX1Sums, 1, sum) NewTargetX1Sums <- as.matrix(NewTargetData) NewTargetX2Sums <- apply(NewTargetX1Sums, 1, sum) Robert Farley Metro www.Metro.net -----Original Message----- From: Erik Iverson [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 29, 2008 19:58 To: Farley, Robert Subject: Re: [R] Trying to "expand" some data - Newbie needs help Farley, Robert wrote: > I want to calculate "expansion factors" for elements in my dataframe > based on a 2-d cross classification. Since I'll have "missing values" > (many combinations will have no record) I'll need a second "expansion > factor" for each "row". I've included my "work to date" below, but I'm > not very close to getting this right. > > Without looking too closely, would it be possible to submit this question to R-help again with a small example of what it is you are looking for? For instance, construct a small, simulated data.frame object like your 'real' one, and then show what you mean by "expansion factors" (i.e, the output you'd like based on your simulated data.frame). This usually helps get a quick, easy answer. Hope that helps! ______________________________________________ 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.