An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-ecology/attachments/20130521/6dba4222/attachment.pl>
Topic: creating an object of class ltraj.
2 messages · Dylann Kersusan, Clément Calenge
Hi Dylann,
I am trying to create an object of class ltraj, but not successfully so far. Here is a sample of my data (GPS relocations): idnr name Date Time Date Time X Y L-00094 Bodil 17/02/04 11:05:52 17/02/2004 11:05:52 1566688 7445760 L-00094 Bodil 17/02/04 14:04:54 17/02/2004 14:04:54 1566392 7444546 L-00094 Bodil 17/02/04 17:01:04 17/02/2004 17:01:04 1566401 7444543 L-00094 Bodil 17/02/04 23:00:42 17/02/2004 23:00:42 1566509 7443853 L-00094 Bodil 18/02/04 02:00:42 18/02/2004 02:00:42 1566813 7443226 and here is my R coding: #Timestamp: date_time into a POSIXct class: timestamp <- as.POSIXct(strptime(as.character(data$Date.Time), "%d/%m/%Y %H:%M:%S"), "GMT") data_timestamp <- data.frame(data, timestamp=timestamp) I also tried this way: date <- as.POSIXct(strptime(paste(data$Date, data$Time), "%d/%m/%Y %H:%M:%S"), "GMT") data_timestamp <- data.frame(data, timestamp=date) (which is not working, dates are displayed Y/M/D and I don't understand why!)
It would be great if you could provide us the output of these commands. For example, to type: head(date) Just a guess: according to your description, it works. Y/M/D is the way the dates are displayed (try to type Sys.time() at the command prompt: it gives the current date and time in POSIX format)
and finally:
#Create a ltraj object:
data_ltraj <- as.ltraj(data, date=timestamp, id=data$name, typeII = TRUE)
and you have to know that I have done that before as well:
#Spatial points data frame:
coordinates(data) <- c("X", "Y")
proj4string(data) <- CRS("+init=epsg:3021")
You don't have to. Objects of class ltraj are not Spatial* objects. Look
at the help page of as.ltraj:
as.ltraj(xy, date, id, burst = id, typeII = TRUE,
slsp = c("remove", "missing"),
infolocs = data.frame(pkey = paste(id, date, sep=".")))
with xy: a data.frame containing the x and y coordinates of the
relocations
if you type coordinates(data) <- c("X","Y"), xy is no longer a
dataframe, but a SpatialPointsDataFrame (check it with class(data)).
So avoid this command before defining your ltraj object. Then, the
following commands should work:
date <- as.POSIXct(strptime(paste(data$Date, data$Time), "%d/%m/%Y
%H:%M:%S"), "GMT")
data_timestamp <- data.frame(data, timestamp=date)
traj <- as.ltraj(data_timestamp[,c("X","Y")], date=date, id=data_timestamp$name, typeII=TRUE)
HTH,
Cl?ment Calenge
From that I either have this warning message:
Erreur dans data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 1, 12328, 0 or the following Messages d'avis :1: In Ops.factor(x1$x, x2$x) : - not meaningful for factors2: In Ops.factor(x1$y, x2$y) : - not meaningful for factors3: In Ops.factor(x$x, x$x[1]) : - not meaningful for factors4: In Ops.factor(x$y, x$y[1]) : - not meaningful for factors5: In Ops.factor(x1$x, x2$x) : - not meaningful for factors6: In Ops.factor(x1$y, x2$y) : - not meaningful for factors7: In Ops.factor(df[-nrow(df), "x"], df[-1, "x"]) : - not meaningful for factors8: In Ops.factor(df[-nrow(df), "y"], df[-1, "y"]) : - not meaningful for factors but only when I enter: data_ltraj <- as.ltraj(data_timestamp, date=timestamp, id=data$name, typeII = TRUE) Am I missing something? Thanx for helping, I appreciate. -- Dylann Kersusan Master Biodiversity and Conservation Zoology dept. Stockholm University [[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology .
Cl?ment CALENGE Cellule d'appui ? l'analyse de donn?es Direction des Etudes et de la Recherche Office national de la chasse et de la faune sauvage Saint Benoist - 78610 Auffargis tel. (33) 01.30.46.54.14