[R] Replace / with - in date

David Winsemius dwinsemius at comcast.net
Thu Apr 15 23:46:15 CEST 2010


It's going to work better if you offer a non-ambiguous version of your  
data. Use dump or dput. If you use the dump route, then see the  
Posting Guide example. If you use dput, then it is as simple as  
dput(object).

Perhaps (if dfrm is the name of a dataframe):

dput(head(dfrm))


On Apr 15, 2010, at 5:27 PM, prem_R wrote:

>
> This is my sample data
>
> 2000/01/01

We cannot tell from the output whether that is a factor or a character  
vector.

> 2000/01/01
> 2000/02/01
> 2000/10/01
> 2000/19/01
> 2000/20/01
> 2000/21/01
> 2000/22/01
> 2000/23/01
> 2000/25/01
> 2000/26/01
> 2000/27/01
> 2000/28/01
> 2000/29/01
>
> Tried using levels function but got the following error .
> Error in levels(a$date) <- gsub("/", "-", levels(a$date)) :
>  attempt to set an attribute on NULL
>
> Thanks.
>
>
> -- 


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list