I can't figure out the syntax I need to get subset to work. I'm trying to split my dataframe into two parts. I'm sure this is a simple issue, but I'm stumped. I either get all or none of the original "rows".> XTTable <- xtabs( ~ direction_ , SurveyData)> XTTabledirection_ EASTBOUND 345 WESTBOUND 307> EBSurvey <- subset(SurveyData, direction_ == "EASTBOUND" )> XTTable <- xtabs( ~ direction_ , EBSurvey)> XTTabledirection_ EASTBOUND 0 WESTBOUND 0> EBSurvey <- subset(SurveyData, direction_ = "EASTBOUND" )> XTTable <- xtabs( ~ direction_ , EBSurvey)> XTTabledirection_ EASTBOUND 345 WESTBOUND 307> EBSurvey <- subset(SurveyData, direction_ == 1 )> XTTable <- xtabs( ~ direction_ , EBSurvey)> XTTabledirection_ EASTBOUND 0 WESTBOUND 0>Robert Farley Metro 1 Gateway Plaza Mail Stop 99-23-7 Los Angeles, CA 90012-2952 Voice: (213)922-2532 Fax: (213)922-2868 www.Metro.net [[alternative HTML version deleted]]
My guess is that you maybe have some leading or trailing spaces in the direction_ variable. Try a tabulation of the direction_ variable to see exactly what values are in your data set. David Scott On Thu, 14 Aug 2008, Farley, Robert wrote:> I can't figure out the syntax I need to get subset to work. I'm trying > to split my dataframe into two parts. I'm sure this is a simple issue, > but I'm stumped. I either get all or none of the original "rows". > > > > > > > > > >> XTTable <- xtabs( ~ direction_ , SurveyData) > >> XTTable > > direction_ > > EASTBOUND > > 345 > > WESTBOUND > > 307 > >> EBSurvey <- subset(SurveyData, direction_ == "EASTBOUND" ) > >> XTTable <- xtabs( ~ direction_ , EBSurvey) > >> XTTable > > direction_ > > EASTBOUND > > 0 > > WESTBOUND > > 0 > >> EBSurvey <- subset(SurveyData, direction_ = "EASTBOUND" ) > >> XTTable <- xtabs( ~ direction_ , EBSurvey) > >> XTTable > > direction_ > > EASTBOUND > > 345 > > WESTBOUND > > 307 > >> EBSurvey <- subset(SurveyData, direction_ == 1 ) > >> XTTable <- xtabs( ~ direction_ , EBSurvey) > >> XTTable > > direction_ > > EASTBOUND > > 0 > > WESTBOUND > > 0 > >> > > > > > > > > > > Robert Farley > > Metro > > 1 Gateway Plaza > > Mail Stop 99-23-7 > > Los Angeles, CA 90012-2952 > > Voice: (213)922-2532 > > Fax: (213)922-2868 > > www.Metro.net > > > > > > > [[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 Scott Department of Statistics, Tamaki Campus The University of Auckland, PB 92019 Auckland 1142, NEW ZEALAND Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 Email: d.scott at auckland.ac.nz Graduate Officer, Department of Statistics Director of Consulting, Department of Statistics
I can't tell exactly what's wrong, just check out the ?str and ?levels functions for some guidance. Farley, Robert wrote:> I can't figure out the syntax I need to get subset to work. I'm trying > to split my dataframe into two parts. I'm sure this is a simple issue, > but I'm stumped. I either get all or none of the original "rows". > > > > > > > > > >> XTTable <- xtabs( ~ direction_ , SurveyData) > >> XTTable > > direction_ > > EASTBOUND > > 345 > > WESTBOUND > > 307 > >> EBSurvey <- subset(SurveyData, direction_ == "EASTBOUND" ) > >> XTTable <- xtabs( ~ direction_ , EBSurvey) > >> XTTable > > direction_ > > EASTBOUND > > 0 > > WESTBOUND > > 0 > >> EBSurvey <- subset(SurveyData, direction_ = "EASTBOUND" ) > >> XTTable <- xtabs( ~ direction_ , EBSurvey) > >> XTTable > > direction_ > > EASTBOUND > > 345 > > WESTBOUND > > 307 > >> EBSurvey <- subset(SurveyData, direction_ == 1 ) > >> XTTable <- xtabs( ~ direction_ , EBSurvey) > >> XTTable > > direction_ > > EASTBOUND > > 0 > > WESTBOUND > > 0 > > > > > > > > > > > Robert Farley > > Metro > > 1 Gateway Plaza > > Mail Stop 99-23-7 > > Los Angeles, CA 90012-2952 > > Voice: (213)922-2532 > > Fax: (213)922-2868 > > www.Metro.net > > > > > > > [[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.
Reasonably Related Threads
- Survey Design / Rake questions
- How do I read a text (.csv) file to match a matrix/cross tab? (Object confusion??)
- Trying to "expand" some data - Newbie needs help
- [Possibly OT] - General question: state of internet traffic
- How do I get xtabs to show missing data?