[R] Simple (?) subset problem
Farley, Robert
FarleyR at metro.net
Fri Aug 15 00:55:38 CEST 2008
BINGO!
> str(SurveyData$direction_)
Factor w/ 2 levels "EASTBOUND
",..: 1 1 1 1 2 2 1 1 2 1 ...
> levels(SurveyData$direction_)
[1] "EASTBOUND " "WESTBOUND
"
>
Was my mistake in how I read the data?
SurveyData <- read.spss("C:/Data/R/orange_delivery.sav",
use.value.labels=TRUE, max.value.labels=Inf, to.data.frame=TRUE)
That brings up 2 more questions:
How do I "trim" the factor names? {or read them correctly}
How do I write to a list the names of factors? {I have another factor
with ~15 "levels" and I'm a REALLY poor typist}
Thanks!
Robert Farley
Metro
www.Metro.net
-----Original Message-----
From: Erik Iverson [mailto:iverson at biostat.wisc.edu]
Sent: Thursday, August 14, 2008 15:47
To: Farley, Robert
Cc: r-help at r-project.org
Subject: Re: [R] Simple (?) subset problem
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.
More information about the R-help
mailing list