Hi Julien,
Works for me:

# Data sets
TripsData1 <- read.table(textConnection("Trip Distance TimeDiff Tripmatch
7329 35,36 172.7453   0.0041     35,36
7371 36,35 172.7453   0.0004     35,36
7372 35,36 172.7453   0.0000     35,36
7373 36,35 172.7453   0.0004     35,36
7374 35,36 172.7453   0.0001     35,36"), header = TRUE)

TripsData2 <- read.table(textConnection("Trip Distance TimeDiff Tripmatch
1617 19,20 1087.365   0.0441     19,20
1899 20,19 1087.365   0.0207     19,20
1915 19,20 1087.365   0.0361     19,20
3285 20,19 1087.365   0.0356     19,20
3826 19,20 1087.365   0.0697     19,20"), header = TRUE)
closeAllConnections()

# Individually
with(TripsData1, aggregate(TripsData1[, 2:3], by = list(Tripmatch),
FUN="mean") )
# Group.1 Distance TimeDiff
# 1   35,36 172.7453    0.001

with(TripsData2, aggregate(TripsData2[, 2:3], by = list(Tripmatch),
FUN="mean") )
#  Group.1 Distance TimeDiff
# 1   19,20 1087.365  0.04124

# Combining both data sets
AllTrips <- rbind(TripsData1, TripsData2)
with(AllTrips, aggregate(AllTrips[, 2:3], by = list(Tripmatch), FUN="mean")
)
# Group.1  Distance TimeDiff
# 1   35,36  172.7453  0.00100
# 2   19,20 1087.3650  0.04124


HTH,
Jorge


On Thu, Sep 24, 2009 at 8:23 AM, Juliane Struve <> wrote:

> Dear all,
>
>
> thanks you very much for replying. However, this does not seem to solve the
> problem.
> I still get the same error message when using TripsData[,2:3].
>
> Is there anything else that could be wrong with this statement or the data
> ? What length is the error message referring to ?
>
> Many thanks,
>
> Juliane
>
>
>  Dr. Juliane Struve
> Environmental Scientist
> 10, Lynwood Crescent
> Sunningdale SL5 0BL
> 01344 620811
>
>
>
> ----- Original Message ----
> From: Paul Emberson <[email protected]>
> To: Juliane Struve <[email protected]>
> Cc: [email protected]
> Sent: Thursday, 24 September, 2009 12:27:00
> Subject: Re: [R] aggregate() - error message
>
> Hi,
>
> Are you trying to get columns 2 and 3 from TripsData in which case you need
> to say TripsData[,2:3] ?
>
> Paul
>
> Juliane Struve wrote:
> > Dear list,
> >  would anybody be able to tell me why the statement
> Tripstatistics=aggregate(TripsData[2:3],by=list(Trip=Tripmatch),FUN="mean")
> >  seems to work well with TripsData 1 but not with TripsData 2 ?
> >  With TripsData 2 it yields  Error in FUN(X[[1L]], ...) : arguments must
> have same length
> >
> > I can't see a difference in the two data sets. Could someone shed light
> on the error message ? Maybe that would help me figure out where the problem
> is.
> >  Thanks very much for any help.  Juliane  PS: The examples below contain
> the  first 5 rows  of my two datafiles.    TripsData 1
> >            Trip Distance TimeDiff Tripmatch
> > 7329 35,36 172.7453  0.0041    35,36
> > 7371 36,35 172.7453  0.0004    35,36
> > 7372 35,36 172.7453  0.0000    35,36
> > 7373 36,35 172.7453  0.0004    35,36
> > 7374 35,36 172.7453  0.0001    35,36
> >
> >  TripsData 2
> >              Trip Distance TimeDiff Tripmatch
> > 1617 19,20 1087.365  0.0441    19,20
> > 1899 20,19 1087.365  0.0207    19,20
> > 1915 19,20 1087.365  0.0361    19,20
> > 3285 20,19 1087.365  0.0356    19,20
> > 3826 19,20 1087.365  0.0697    19,20
> >
> >
> >
> >
> > ______________________________________________
> > [email protected] 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]]

______________________________________________
[email protected] 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.

Reply via email to