Hi,
I am really confused how ddply work, so maybe you can help me.
I created a function that sorts a vector etc.
fn <- function(x){
x1 <- sort(x)
x2 <- seq(length(x))
x3 <- x2/max(x2)
df <- data.frame(x1,x2,x3)
df
}
Probably this is not the best form of the function, but at least it produces what I want (data to plot a cumulative count curve).
This function works on a single vector but I have a melted dataframe like:
var1 <- rep(c("a","b"),c(100,100))
var2 <- runif(200,1,50)
df.test <- data.frame(var1,var2)
..and I want to apply that function on var2 but splitted by the variable var1. I think this might be a case for ddply...
anything like: ddply(df.test,.(var1),fn(var2))...
maybe someone know how to do that (modifying my function and applying it on a splitted dataframe).
Best regards,
Johannes
Correct use of ddply with own function
2 messages · Johannes Radinger, Tal Galili
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120505/8ef0e469/attachment.pl>