[R] noob requesting help

capital_P petervw48 at hotmail.com
Mon Jun 18 12:09:49 CEST 2012


David Winsemius wrote
> 
> That's going to remove a lot of rows.
> 
> Since you are not telling us what columns correspond to those  
> concepts, I'm going to use the terms you are. Something along the  
> lines of:
> 
> require(lattice)
> histogram( ~ hours | bird,  data=dat2, nint =24 , xlim=c(0,24))
> histogram( ~ hours ,        data=dat2,  nint =24 , xlim=c(0,24))
> 
> The result on that example was just a list with one element, a  
> dataframe.
> 
>  > str(departures)
> List of 1
>   $ 121.3:'data.frame':	1 obs. of  4 variables:
>    ..$ device_info_serial: int 121
>    ..$ hour              : int 10
>    ..$ time              : POSIXct[1:1], format: "2009-05-21 04:59:24"
>    ..$ tripID            : int 3
> 
> So to get what you might have expected
> 
>  > dep <- departures[[1]]
>  > dep
>    device_info_serial hour                time tripID
> 1                121   10 2009-05-21 04:59:24      3
> 
> But since you didn't actually describe what you did want (or if you  
> did you left upthread), its only a guess.
> 

I'll try to explain my goals more clearly.

The columns are:

dat2$device_info_serial: The 'number' of the bird, ranging from 121 to 542.
There are 34 different birds, each with their own number.

dat2$tripID: The number of the trip. Every bird has a trip 1, 2, 3, etc.
(some birds have as much as 265 trips, many have less). Every trip has many
measurements, as trips take hours and measurements were taken every 15
minutes.

dat2$time: The time at which a measurement was taken.

dat2$hour: The 'hour' part of dat2$time; the hour in which a measurement was
taken


>From my dataset, I need to gather only the first measurement of every trip
of every bird. This way, I can make (circular) graphs of the departure-times
for each trip of each bird. I think that I am very close after using:

departures <- lapply(split(dat2, list(dat2$device_info_serial,
dat2$tripID)), function(x) x[x$time == min(x$time),]) 

But it is in the wrong format. I need it to be in a format so that I can use
commands such as departures$hour and departures$device_info_serial. I need
this so that I can circulise (circularise?) dat2$hour and so that I can make
graphs for each bird seperately.

Making the graphs etc. shouldn't be a problem if I have a dataset that I can
use like this:

d121 <- departures[which(departures$device_info_serial == 121),]
d130 <- departures[which(departures$device_info_serial == 130),]
d132 <- departures[which(departures$device_info_serial == 132),]
d133 <- departures[which(departures$device_info_serial == 133),]

and

cdAll <- circular(departures$hour, units='hours', template='clock24')
cd121 <- circular(d121$hour, units='hours', template='clock24')
cd130 <- circular(d130$hour, units='hours', template='clock24')
cd132 <- circular(d132$hour, units='hours', template='clock24')

So, if I'm not mistaken, I only need your help with transforming the
'departures' that I have now into something with $hour and
$device_info_serial. I hope this is possible.

I hope my ignorance isn't frustrating you too much. I'm trying my best to
understand and learn how to work with R in the short timespan that I have.

Peter

--
View this message in context: http://r.789695.n4.nabble.com/noob-requesting-help-tp4632803p4633678.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list