Skip to content

Instantly share code, notes, and snippets.

@holgerbrandl
Last active August 29, 2015 14:01
Show Gist options
  • Save holgerbrandl/6ba45dfb3e09ddcea7b6 to your computer and use it in GitHub Desktop.
Save holgerbrandl/6ba45dfb3e09ddcea7b6 to your computer and use it in GitHub Desktop.
Example for ddply numerics problem
library(plyr)
exampleData <- structure(list(movie = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "my_movie", class = "factor"),
normS1 = c(-0.00000514991529017386, 0.00000434044351014654,
0.000011374474150384, 0.00000791328447026715, 0.00000180037689006078,
-0.00000259589226008764, -0.000014779838190499, -0.0000025679794400867,
-0.0000208090073107025, -0.00000607103835020496, 0.00000872275625029448,
-0.00000428461787014465, -0.000000851341010028744, -0.00000168872561005701,
0.00000796911011026904, 0.00000787141524026574, 0.00000436835633014748,
0.00000336349481011355, -0.00000706194346023841, -0.00000343327686011591
)), .Names = c("movie", "normS1"), row.names = c(NA, 20L), class = "data.frame")
meanLast <- ddply(exampleData, .(movie), summarize,
a="test",
avgNormS1=1*mean(normS1)
)
meanFirst <- ddply(exampleData, .(movie), summarize,
avgNormS1=1*mean(normS1),
a="test"
)
meanLast
meanFirst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment