Re: [R] pivot table in R

2008-01-29 Thread Christos Hatzis
AM > To: [EMAIL PROTECTED]; r-help@r-project.org > Subject: Re: [R] pivot table in R > > A = read.table("clipboard", header=TRUE) > > A > sex age region no_of_accidents > 1 F young north 10 > 2 F young south 12 > 3 F ol

Re: [R] pivot table in R

2008-01-29 Thread John Kane
Have a look at the reshape package. With your data as data.frame xx : library(reshape) dd <- melt(xx, id=c("sex", "age", "region"),measured=c(no_of_accidents)); dd cast(dd, sex~variable, sum) --- [EMAIL PROTECTED] wrote: > Hello, > > I'm struggling with an elementary problem with R. I > have

Re: [R] pivot table in R

2008-01-29 Thread hadley wickham
> I'm struggling with an elementary problem with R. I have a simple data > frame such as this one giving the number of accidents subdivided by sex, > age and region. If you're trying to do pivot tables in R, I'd recommend looking at the reshape package, which was designed specifically to tackle th

Re: [R] pivot table in R

2008-01-29 Thread David Winsemius
[EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED] k: Three or four solutions have already been offered. Here is (yet) another: > Atxt <- " + sex age region no_of_accidents + 1 F young north 10 + 2 F young south 12 + 3 F old north 5 + 4 F

Re: [R] pivot table in R

2008-01-29 Thread Attiglah, Mama
MAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: 29 January 2008 12:05 To: r-help@r-project.org Subject: [R] pivot table in R Hello, I'm struggling with an elementary problem with R. I have a simple data frame such as this one giving the number of accidents

Re: [R] pivot table in R

2008-01-29 Thread Romain Francois
Hi Pietro, Depending on the actual structure you want in the output, you can use some of the functions in the apply family, particularly tapply, aggregate, or by. Something like : R> tapply( d[["no_of_accidents" ]], d[[ "sex" ]], sum ) F M 34 83 R> aggregate( d["no_of_accidents" ], d[ "sex" ],

[R] pivot table in R

2008-01-29 Thread pietro . parodi
Hello, I'm struggling with an elementary problem with R. I have a simple data frame such as this one giving the number of accidents subdivided by sex, age and region. sex age region no_of_accidents F young north 10 F young south 12 F o