As an example, I want a function that will iterate over the columns in a dataframe and print out each column’s data type (e.g., “numeric”, “integer”, “character”, etc)
Without a variable I know I can do class(df$MyColumn) and get the data type. How can I change it so “MyColumn” is a variable?
What I’m trying is
f <- function(df) {
for(column in names(df)) {
columnClass = class(df[column])
print(columnClass)
}
}
But this just prints out [1] "data.frame" for each column.
Use a comma before
column: