Hi, I have the following problem: I have a list of entries with vehicles going from some places to others and the time that they need. e.g. Vehicle Start End Time 1 A B 5 2 A C 4 3 A C 3 4 B A 6 5 B C 4 6 B C 6 7 C B 2 8 C B 4 9 A B 7 What I need is a 2d table with the average time needed from Start to End, e.g. A B C A NA 6 3.5 B 6 NA 5 C NA 3 NA Any help would be very much appreciated, Sugi -- View this message in context: http://r.789695.n4.nabble.com/Create-2d-table-with-mean-of-entries-tp2966610p2966610.html Sent from the R help mailing list archive at Nabble.com.
Try this: with(DF, tapply(Time, list(Start, End), mean)) On Thu, Oct 7, 2010 at 8:40 AM, sugimoto <ieyasu@sugimoto.at> wrote:> > Hi, > > I have the following problem: > I have a list of entries with vehicles going from some places to others and > the time that they need. > e.g. > Vehicle Start End Time > 1 A B 5 > 2 A C 4 > 3 A C 3 > 4 B A 6 > 5 B C 4 > 6 B C 6 > 7 C B 2 > 8 C B 4 > 9 A B 7 > > What I need is a 2d table with the average time needed from Start to End, > e.g. > A B C > A NA 6 3.5 > B 6 NA 5 > C NA 3 NA > > > Any help would be very much appreciated, > Sugi > -- > View this message in context: > http://r.789695.n4.nabble.com/Create-2d-table-with-mean-of-entries-tp2966610p2966610.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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Hi: Perhaps> dd <- read.table(textConnection("+ Vehicle Start End Time + 1 A B 5 + 2 A C 4 + 3 A C 3 + 4 B A 6 + 5 B C 4 + 6 B C 6 + 7 C B 2 + 8 C B 4 + 9 A B 7"), header = TRUE)> closeAllConnections()with(dd, xtabs(Time ~ Start + End)/table(Start, End)) End Start A B C A 6.0 3.5 B 6.0 5.0 C 3.0 Interesting output :) HTH, Dennis On Thu, Oct 7, 2010 at 4:40 AM, sugimoto <ieyasu@sugimoto.at> wrote:> > Hi, > > I have the following problem: > I have a list of entries with vehicles going from some places to others and > the time that they need. > e.g. > Vehicle Start End Time > 1 A B 5 > 2 A C 4 > 3 A C 3 > 4 B A 6 > 5 B C 4 > 6 B C 6 > 7 C B 2 > 8 C B 4 > 9 A B 7 > > What I need is a 2d table with the average time needed from Start to End, > e.g. > A B C > A NA 6 3.5 > B 6 NA 5 > C NA 3 NA > > > Any help would be very much appreciated, > Sugi > -- > View this message in context: > http://r.789695.n4.nabble.com/Create-2d-table-with-mean-of-entries-tp2966610p2966610.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]]
Thanks, I am using with(DF, tapply(Time, list(Start, End), mean)) which works as wanted. Sugi -- View this message in context: http://r.789695.n4.nabble.com/Create-2d-table-with-mean-of-entries-tp2966610p2967913.html Sent from the R help mailing list archive at Nabble.com.