Hello,
I'm trying to write a simple function but I failed. I know It isn't very complicated, but I couldn't fix my code. This is the code:
dfeze=function(x,y) {
nam1=paste(paste(y,"id_d",sep="$"),"[",paste(y,x,sep="$"),"==1","]",sep="")
nam2=paste(paste(y,"strat",sep="$"),"[",paste(y,x,sep="$"),"==1","]",sep="")
dim(table(as.formula(nam1,nam2)))[1]-dim(table(as.formula(nam1,nam2)))[2]
}
As you can see, I am using strings in order enter that text in the table function.
The idea is to tabulate some result employing the 2 variables (id_d and strat), in reference to the data frame defined by "y".
The condition I am entering inside the table function is based on the value equal to 1 for the variable "x". After all that, I just extract the result from the subtraction of rows and column from this simple tabulate. However, I receive the message:
Error in formula.default(eval(parse(text = x, keep.source = FALSE)[[1L]])) :
invalid formula
Can you guide me?
Again, the idea in the future is entering the data frame and the variable that is equal to 1 in the function. A simple idea, but beyond my programming knowledge I am afraid.