I'd like to create a function X which applies another function Y to several variables.
Function Y
DplotV <- function (id,x){
D <- as.data.frame(cbind(id,x))
x1 <- as.data.frame(D[order(x),])
dotchart(x1$x,labels=id,pch=16)
}
DplotV(mydata$id,mydata$blood)
This basically sorts the id and the variable x by the variable x and creates a dotplot. I've also created some code which names the chart and saves it by taking the x variable name, which I've not included here. In the full function I also have other parameters such as color etc... so writing the function for each variable becomes a repetitive and long task.
When working on a big dataset it would be ideal to plot several variables by the same id variable.
Is there a way to apply the function above to each variable in the dataset (but always using the same id variable?)
Ideally I'd like a function (e.g. DplotData) which applies DplotV to all the variables in the dataset (except the id var if possible), so that I can just write DplotData(mydata$id,mydata)
and the function will loop through all the dataset variables (blood and weight in this case).