[R] help with mysql and R: partitioning by quintile

Phil Spector spector at stat.berkeley.edu
Mon May 9 00:52:19 CEST 2011


One way to get the ratings would be to use the ave() function:

rating = ave(x$freq,x$track,
              FUN=function(x)cut(x,quantile(x,(0:5)/5),include.lowest=TRUE))

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu



On Sun, 8 May 2011, gj wrote:

> Hi,
>
> I have a mysql table with fields userid,track,frequency e.g
> u1,1,10
> u1,2,100
> u1,3,110
> u1,4,200
> u1,5,120
> u1,6,130
> .
> u2,1,23
> .
> .
> where "frequency" is the number of times a music track is played by a
> "userid"
>
> I need to turn my 'frequency' table into a rating table (it's for a
> recommender system). So, for each user, I need to categorise the frequency
> of tracks played by quintile so that each particular track can have 5
> ratings (1-5), with the ratings allocated as follows: inter-quintile range
> 100-80% = rating 5,   inter-quintile range 80-60% = rating 4,
> ..., inter-quintile range 20-0% = rating 1)
>
> Hence, I need to create a table with fields userid,track,rating:
> u1,1,1
> u1,2, 3
> ...
>
> Can anybody help me to do this with R?
>
> Regards
> Gawesh
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list