0

Example Data:

df1 <- as.data.frame(rbind(c(1,2,3), c(1, NA, 4), c(NA, NA, NA), c(4,6,7), c(4, 8, NA)))
df2 <- as.data.frame(rbind(c(1,2,3), c(1, NA, 4), c(4,6,7), c(NA, NA, NA), c(4, 8, NA)))

dfList <- list(df1,df2)
colnames <- c("A","B","C") 

dfList[[1]]

  V1 V2 V3
1  1  2  3
2  1 NA  4
3 NA NA NA
4  4  6  7
5  4  8 NA

dfList[[2]]

  V1 V2 V3
1  1  2  3
2  1 NA  4
3  4  6  7
4 NA NA NA
5  4  8 NA

I would like to do some checks on my list of data.frames. For example, see if all the columns in the first data.frame have the same classes as the columns in the other data.frames. I thought I'd try:

dfList <- lapply(dfList , function(x) lapply(class(x)))

But that does not work. What would be the correct syntax for this?

Tom
  • 2,173
  • 1
  • 17
  • 44

1 Answers1

0

Credit to @det (see comments).

dfList <- lapply(dfList , function(x) lapply(x, class))
Tom
  • 2,173
  • 1
  • 17
  • 44