
# Trim white space (leading and/or trailing). Includes tabs.
trim <- function(str)gsub('^[[:space:]]+', '', gsub('[[:space:]]+$', '', str))

#
levels(SurveyData$direction_) <- trim(levels(SurveyData$direction_))

> Date: Thu, 14 Aug 2008 15:55:38 -0700
> From: FarleyR@metro.net
> To: r-help@r-project.org
> Subject: Re: [R] Simple (?) subset problem
> 
> 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@biostat.wisc.edu] 
> Sent: Thursday, August 14, 2008 15:47
> To: Farley, Robert
> Cc: r-help@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@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-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.

_________________________________________________________________

 Contest

	[[alternative HTML version deleted]]

