[R] Grouping variables in a data frame

Liviu Andronic landronimirc at gmail.com
Sat Aug 27 12:11:20 CEST 2011


On Sat, Aug 27, 2011 at 7:26 AM, Andra Isan <andra_isan at yahoo.com> wrote:
> Hi All,
>
> I have a data frame as follow:
>
> user_id time age location gender
> .....
>
> and I learn a logistic regression to learn the weights (glm with family= (link = logit))), my response value is either zero or one. I would like to group the users based on user_id and time and see the y values and predicted y values at the same time. Or plot them some how. Is there any way to somehow group them together so that I can learn more about my data by grouping them?
>
It's very difficult to help you because you haven't followed the
posting guide. But I suspect you're looking for the following:

> require(plyr)
Loading required package: plyr
> data(mtcars)
> ##considering 'gear' as 'id' and 'carb' as time
> ddply(mtcars, .(gear, carb), function(x) mean(x$hp))
   gear carb    V1
1     3    1 104.0
2     3    2 162.5
3     3    3 180.0
4     3    4 228.0
5     4    1  72.5
6     4    2  79.5
7     4    4 116.5
8     5    2 102.0
9     5    4 264.0
10    5    6 175.0
11    5    8 335.0

This will compute the mean of 'hp' for each group of id & time.
Liviu


> I would like to get these at the end
> user_id time y predicted_y
>
> Thanks a lot,
> Andra
>
> ______________________________________________
> R-help at 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.
>



-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail



More information about the R-help mailing list