Assume that I have several dataframes in a workspace in R and I want a list of the names of the columns in all the dataframes.
I thought the following would work. But it does not. Try it in your own workspace.
sapply(ls(),names)
Why does it not work? ls() creates a list of all the dataframes and then names function should be applied to each dataframe. That is my simple question for now.
Coming next: I want to determine all the columns that have a name with the letters “date” in them so that I can the apply the following function to each of those columns no matter what dataframe they are in.
as.Date(dataframe$dateofenrollment,origin="1899-12-30")
It doesn’t work because
ls()returns the names of the objects in our workspace, not the objects themselves.You probably want something like the following:
This will have
NULLelements for any objects that are not data frames, but presumably you can work around that.