首页 > 解决方案 > Tabulate column containing list in R

问题描述

I am using sapply (or lapply for what matters here) to tabulate the classes of a data frame.

f<-as.POSIXct(c("2014-10-02","2016-11-05","2014-09-11"))
dd<-c(1,12,22)
fr<-c("coo","foo","doo")

df<-cbind.data.frame(f,dd,fr)

c<-sapply(df,class)

This generates an error when, as for the case of the posixct class, the class in a list of 2 elements.

table(c)
Error in table(c) : all arguments must have the same length

c
$`f`
[1] "POSIXct" "POSIXt" 

$dd
[1] "numeric"

$fr
[1] "factor"

Obviously unlist will not work as the double class is then counted as 2 separate classes. How do I collapse the double class in a unitary element here?

标签: rlistdataframe

解决方案


推荐阅读