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

Edzer Pebesma edzer.pebesma at uni-muenster.de
Thu Jun 23 20:40:44 CEST 2011


Hi Raphaelle,

I can't see what went wrong. Please provide a script, or the shapefile
with script (possibly off-list) to reproduce the problem.

The printing of Date and yearmon data with quotes is standard behaviour,
and does not indicate they are transformed or so, or of another class. Try:

class(Centroid_SA at data$rvf_date)

Have you tried, as an alternative, to read the shapefile with function
readOGR in package rgdal?

On 06/23/2011 06:48 PM, Raphaelle wrote:
> 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.
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list