Hi:

Try this:

> d <- read.table(textConnection("
+          procedure property sensor_data              sensor_date
+ 1    S_10     nord    626821.0 2002-09-30T00:00:00+0200
+ 2     S_10     nord    626821.0 2002-12-05T00:00:00+0100
+ 3    S_10     nord    626821.1 2008-07-31T00:00:00+0200
+ 4  S_1000     nord    626496.8 2002-09-30T00:00:00+0200
+ 5  S_1000     nord    626496.8 2002-12-05T00:00:00+0100
+ 6  S_1000     nord    626496.9 2009-04-23T00:00:00+0200
+ 7  S_1000     nord    626497.0 2009-11-10T00:00:00+0100
+ 8     S_1     nord    626485.3 2002-09-30T00:00:00+0200
+ 9    S_1     nord    626485.3 2002-12-05T00:00:00+0100
+ 10    S_1     nord    626485.3 2003-02-07T00:00:00+0100"), header = TRUE)
# Create a new date variable - the HMS+ seem to be overkill here :)
d$sensor_date <- as.character(d$sensor_date)
d$stime <- as.Date(substring(d$sensor_date, 1, 10))

# Create a function to determine the minimum time and produce the
differences
# in sensor_data - works for a generic input data frame
> f <- function(df) {
+      mint <- which.min(df$stime)
+      df$difference <- with(df, sensor_data - sensor_data[mint])
#      df$stime <- NULL        # optional: knocks out the created date
variable
+      df
+     }

# Use the ddply() function in package plyr to map f to each subset data
frame
# defined by procedure:
> library(plyr)
> ddply(d, .(procedure), f)
   procedure property sensor_data              sensor_date      stime
difference
1        S_1     nord    626485.3 2002-09-30T00:00:00+0200 2002-09-30  0.0
2        S_1     nord    626485.3 2002-12-05T00:00:00+0100 2002-12-05  0.0
3        S_1     nord    626485.3 2003-02-07T00:00:00+0100 2003-02-07  0.0
4       S_10     nord    626821.0 2002-09-30T00:00:00+0200 2002-09-30  0.0
5       S_10     nord    626821.0 2002-12-05T00:00:00+0100 2002-12-05  0.0
6       S_10     nord    626821.1 2008-07-31T00:00:00+0200 2008-07-31  0.1
7     S_1000     nord    626496.8 2002-09-30T00:00:00+0200 2002-09-30  0.0
8     S_1000     nord    626496.8 2002-12-05T00:00:00+0100 2002-12-05  0.0
9     S_1000     nord    626496.9 2009-04-23T00:00:00+0200 2009-04-23  0.1
10    S_1000     nord    626497.0 2009-11-10T00:00:00+0100 2009-11-10  0.2

HTH,
Dennis

On Tue, Feb 1, 2011 at 1:52 AM, alcesgabbo <alcesgabbo@hotmail.com> wrote:

>
> Hello everybody.
>
> I have this object
>
>          procedure property sensor_data              sensor_date
> 1    S_10     nord    626821.0 2002-09-30T00:00:00+0200
> 2     S_10     nord    626821.0 2002-12-05T00:00:00+0100
> 3    S_10     nord    626821.1 2008-07-31T00:00:00+0200
> 4  S_1000     nord    626496.8 2002-09-30T00:00:00+0200
> 5  S_1000     nord    626496.8 2002-12-05T00:00:00+0100
> 6  S_1000     nord    626496.9 2009-04-23T00:00:00+0200
> 7  S_1000     nord    626497.0 2009-11-10T00:00:00+0100
> 8     S_1     nord    626485.3 2002-09-30T00:00:00+0200
> 9    S_1     nord    626485.3 2002-12-05T00:00:00+0100
> 10    S_1     nord    626485.3 2003-02-07T00:00:00+0100
>
> the third colomn (sensor_data) is a distance in meters.
> each distance has a date (sensor_date)
> for each row I would like to find the difference from the first distance
> (with the min date) and the distance.
>
> I know it's difficult to understand.. I give you an example:
>
> for the first procedure S_10 I should find the first distance based on the
> date:
>
> distance:    626821.0   with the date: 2002-09-30T00:00:00+0200
>
> then I should do the difference between the current distance and the first
> distance:
>
> 626821.0 - 626821.0 = 0.0
>  626821.0 -  626821.0 = 0.0
> 626821.1 - 626821.0 = 0.1
>
> Then I should do this also for the other procedures.
>
> I would like a resut like this:
>
>     procedure property sensor_data              sensor_date     difference
> 1    S_10     nord    626821.0 2002-09-30T00:00:00+0200    0.0
> 2     S_10     nord    626821.0 2002-12-05T00:00:00+0100   0.0
> 3    S_10     nord    626821.1 2008-07-31T00:00:00+0200   0.1
> 4  S_1000     nord    626496.8 2002-09-30T00:00:00+0200  0.0
> 5  S_1000     nord    626496.8 2002-12-05T00:00:00+0100   0.0
> 6  S_1000     nord    626496.9 2009-04-23T00:00:00+0200    0.1
> 7  S_1000     nord    626497.0 2009-11-10T00:00:00+0100   0.2
> 8     S_1     nord    626485.3 2002-09-30T00:00:00+0200     0.0
> 9    S_1     nord    626485.3 2002-12-05T00:00:00+0100      0.0
> 10    S_1     nord    626485.3 2003-02-07T00:00:00+0100     0.0
>
> How can I do this procedure?????
>
>
> Thanks
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/multi-Operations-on-a-matrix-tp3250807p3250807.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> 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.
>

	[[alternative HTML version deleted]]

