motiur
motiur

Reputation: 1680

Use apply with table in R

I have two variables, one is dependent and another one is independent variable. The dependent variable is x and the independent variable is y. The dependent variable is itself a matrix and it can be iterated as x[,1:n]; same goes for the independent variable .The independent variable can be iterated as y[,1:n]. Now for one single instance of the variable - I would use the table function in R to find ROC like so : table(y[,1], round(x[,1]). I want to use apply function out here so that I can iterate both the variables at the same time - something like apply(ind_var,dep_var,2,function(x,y){x,round(y)}) This can easily be done using a for loop - can it be done using apply?

Thanks

Upvotes: 0

Views: 1166

Answers (1)

lmo
lmo

Reputation: 38510

Try using sapply:

sapply(1:ncol(x), function(i) table(y[,i], round(x[,i]))

Upvotes: 1

Related Questions