[R] Casting Date to char
Duncan Murdoch
murdoch@dunc@n @end|ng |rom gm@||@com
Wed Sep 5 22:30:26 CEST 2018
On 05/09/2018 4:17 PM, Rich Shepard wrote:
> I've read the help for as.Date: "Date Conversion Functions to and from
> Character" but the method as.character(x ...) isn't working for me:
>
>> str(dp)
> 'data.frame': 113569 obs. of 2 variables:
> $ rainfall.sampdate: Date, format: "2005-01-01" "2005-01-02" ...
> $ rainfall.prcp : num 0.59 0.08 0.1 0 0 0.02 0.05 0.1 0 0.02 ...
>> dp$sampdate <- as.Character(dp$sampdate)
> Error in `$<-.data.frame`(`*tmp*`, sampdata, value = character(0)) :
> replacement has 0 rows, data has 113569
This might just be a typo in your message, but as.character() is the
function you want, not as.Character().
The other typo or error above is that you are trying to convert
dp$sampdate, but the dataframe has no column with that name according to
the lines above.
Duncan Murdoch
>
> I don't understand the error message and want to learn what I've done
> incorrectly.
>
> Regards,
>
> Rich
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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