Reputation: 672
I want to write an automated code in R for generating summary and table.
Statistics for variables based on their data types. for. e.g
If data type = Numeric, display summary();
If data type = factor, display table();
Please help me.
Thanks Balaji
Upvotes: 1
Views: 73
Reputation: 826
This should do it
data <- data.frame(a=rnorm(4), b=c("a", "a", "b", "b"), c=c(TRUE, FALSE, TRUE, FALSE))
Display <- function(x) {
switch(
EXPR = class(x),
factor = {
print(table(x))
},
numeric = {
print(summary(x))
},
print("not supported type")
)
}
Display(data$a)
Display(data$b)
Display(data$c)
Upvotes: 1