User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

group_by_pivoting_made_easy_with_ddply_package [2015/08/12 14:41] (current)
vincenzo created
Line 1: Line 1:
 +<code java>
 +#import data
 +#df <- read.csv("​C:/​Users/​Vincenzo Grasso/​Desktop/​NG.csv",​sep = ","​)
 +#​df$cluster=gsub("​_","",​gsub("​\\d","",​ gsub("​]([^/​]*)$","​]",​df$Campaign)))
 +Apply the pivoting:
 +1. Decide the variable id that on which applying the operations
 +2. Define the function
 +3. that's it.
 +<code java>
 +# group by
 +df <- ddply(df, c("​cluster"​),​ function(df) data.frame(sumclicks=sum(df$Clicks),​ sumimpressions=sd(df$Impressions)))
 +Plot the result:
 +<code java>
 +p <- ggplot(df, aes(x=sumimpressions,​ y=sumclicks,​ label=rownames(df$cluster))) + geom_text(size=4,​ label=df$cluster)
 +p  + scale_x_log10()
group_by_pivoting_made_easy_with_ddply_package.txt ยท Last modified: 2015/08/12 14:41 by vincenzo