Re: [R] trimming a factor

2006-03-10 Thread Francisco J. Zagmutt
RSiteSearch("trim") or RSiteSearch("trim space") will get you there.

Francisco

>From: "Dan Chan" <[EMAIL PROTECTED]>
>To: 
>Subject: [R] trimming a factor
>Date: Fri, 10 Mar 2006 15:52:03 -0500
>
>Hi,
>
>I have the following dataframe.  The County Column has many empty spaces
>at the end.
>I want to cut out the empty space and put them back into the dataframe.
>How can this be done?
>
> > head(DailyCounty)
>  Date   County GFCPer GFCEquip Acre nFires
>Date2
>1 2001-01-04 00:00:00 Appling   11 0.20  1
>2001-01-04
>2 2001-01-05 00:00:00 Appling   22 0.13  1
>2001-01-05
>3 2001-01-06 00:00:00 Appling   11 3.41  1
>2001-01-06
>4 2001-01-07 00:00:00 Appling   11 0.18  1
>2001-01-07
>5 2001-01-10 00:00:00 Appling   11 5.10  1
>2001-01-10
>6 2001-01-16 00:00:00 Appling   11 0.48  1
>2001-01-16
>
> >sub(' +$','',levels(DailyCounty$County))
>"Appling"
>
> >sub(' +$','',DailyCounty$County)
>[1] "1"
>
>Thank you!
>
>
>Daniel Chan
>Meteorologist
>Georgia Forestry Commission
>P O Box 819
>Macon, GA
>31202
>Tel: 478-751-3508
>Fax: 478-751-3465
>
>__
>R-help@stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! 
>http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] trimming a factor

2006-03-10 Thread Sundar Dorai-Raj


Dan Chan wrote:
> Hi, 
> 
> I have the following dataframe.  The County Column has many empty spaces
> at the end.
> I want to cut out the empty space and put them back into the dataframe.
> How can this be done?  
> 
> 
>>head(DailyCounty)
> 
>  Date   County GFCPer GFCEquip Acre nFires
> Date2
> 1 2001-01-04 00:00:00 Appling   11 0.20  1
> 2001-01-04
> 2 2001-01-05 00:00:00 Appling   22 0.13  1
> 2001-01-05
> 3 2001-01-06 00:00:00 Appling   11 3.41  1
> 2001-01-06
> 4 2001-01-07 00:00:00 Appling   11 0.18  1
> 2001-01-07
> 5 2001-01-10 00:00:00 Appling   11 5.10  1
> 2001-01-10
> 6 2001-01-16 00:00:00 Appling   11 0.48  1
> 2001-01-16
> 
> 
>>sub(' +$','',levels(DailyCounty$County))
> 
> "Appling" 
> 
> 
>>sub(' +$','',DailyCounty$County)
> 
> [1] "1"
> 

I think you want:

DailyCounty$County <-
   factor(sub(' +$', '', as.character(DailyCounty$County)))


HTH,

--sundar

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] trimming a factor

2006-03-10 Thread Dan Chan
Hi, 

I have the following dataframe.  The County Column has many empty spaces
at the end.
I want to cut out the empty space and put them back into the dataframe.
How can this be done?  

> head(DailyCounty)
 Date   County GFCPer GFCEquip Acre nFires
Date2
1 2001-01-04 00:00:00 Appling   11 0.20  1
2001-01-04
2 2001-01-05 00:00:00 Appling   22 0.13  1
2001-01-05
3 2001-01-06 00:00:00 Appling   11 3.41  1
2001-01-06
4 2001-01-07 00:00:00 Appling   11 0.18  1
2001-01-07
5 2001-01-10 00:00:00 Appling   11 5.10  1
2001-01-10
6 2001-01-16 00:00:00 Appling   11 0.48  1
2001-01-16

>sub(' +$','',levels(DailyCounty$County))
"Appling" 

>sub(' +$','',DailyCounty$County)
[1] "1"

Thank you! 


Daniel Chan
Meteorologist
Georgia Forestry Commission
P O Box 819
Macon, GA 
31202
Tel: 478-751-3508
Fax: 478-751-3465

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html