[R-sig-Geo] as.yearmon in attribute table of shapefiles

Raphaelle metras.raphaelle at choisyclub.org
Thu Jun 23 18:48:15 CEST 2011


Dear all,

I am experiencing troubles with Dates objects in shapefiles:

1. I open my shapefile using readShapePoints from maptools : ok.

2. Within the shapefile, the date appears correctly as Class Date (which is
good):
> str(Centroid_SA at data$rvf_date[44569:44577])
Class 'Date'  num [1:9] NA 14706 NA NA 14741 ...

3. but when I display all the dates, it appears in " ", as if it was a
character:
[44569] NA   "2010-04-07" NA  NA "2010-05-12" NA NA NA

4. This becomes a problem because want to work on these dates. I use the
as.yearmon function from the 'zoo' package because I want to work with
monthly
data.

Centroid_SA at data$rvf_dateym <- as.yearmon(Centroid_SA at data$rvf_date)

5. I display the new vector date I just created, still appearing in " ":
[44561] NA NA NA NA NA NA NA   NA   NA    "Apr 2010"
[44571] NA  NA  "May 2010" NA 

6. and then when I want to open the attribute table, I have the following
message
(see below) and I can't work anymore with the variable.

> head(Centroid_SA at data)
Error in charToDate(x) : 
  character string is not in a standard unambiguous format

7. I have tried the function as.yearmon with a normal dataset (not
shapefile), and
I have no problem. All works fine. The only difference apparently is the
presence
of " " in steps 3 & 5, that are not appearing when I use normal dataset.

8. I have also extracted the attribute table from the shapefile to work with
it
independently, trying to reformat in as.Date etc but the problem remains.

Thank you very much if someone could give me some hints.

Best regards,

Raphaelle Metras


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/as-yearmon-in-attribute-table-of-shapefiles-tp6509058p6509058.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list