I have created a code to obtain statistics on a variable and I would like to automate it in a function to use it on other variables.
Name of the dataframe: data Name of the variable: UNIQUE
Code:
table1 <- table(data$UNIQUE, useNA = "ifany", dnn = "Variables")
dataframe1 <- as.data.frame(table1, row.names = NULL, responseName = "N")
dataframe1$N <- as.numeric(dataframe1$N)
Now I'm trying to do the function using the table and the variable in arguments like:
function1 <- function(Table, Variable){
table1 <- table(Table$Variable, useNA = "ifany", dnn = "Variables")
dataframe1 <- as.data.frame(table1, row.names = NULL, responseName = "N")
dataframe1$N <- as.numeric(dataframe1$N)
dataframe1
}
I tried with the assign and paste functions but I couldn't find the solution.
Thanks by advance, Pierre