我有下面的示例数据框,我想使用R创建一个新的数据框,它有2列。第一列将命名为"Name"
,并将包括数据集的所有列名。数据集每次都不同,因此列数可能会有所不同。第二列将命名为"Class"
,并将包括每列的class()
。
structure(list(case_id = c("3397364", "3397364"), action = c("3397364-RAAMELK",
"3397364-RAAMELK"), resource = c("RAAMELK", "RAAMELK"), lifecycle = c(1,
1), registration_type = structure(1:2, .Label = c("start", "complete"
), class = "factor"), timestamp = structure(c(1667523600, 1667531220
), tzone = "UTC", class = c("POSIXct", "POSIXt")), activity = c("RAAMELK",
"RAAMELK"), activity_description = c("Forbrukt r<e5>melk", "Forbrukt r<e5>melk"
), ...9 = c(NA, NA), product = c("K101152", "K101152"), product_type_text = c("200100 - Milk",
"200100 - Milk"), qty = c(NA, 31), in_out = c("in", "out"), qty_scrap = c(NA_real_,
NA_real_), `FP ordre` = c(NA_character_, NA_character_), Artikkeltype = c("SF",
"SF"), .order = 1:2), row.names = c(NA, -2L), class = c("eventlog",
"log", "tbl_df", "tbl", "data.frame"), case_id = "case_id", activity_id = "activity", activity_instance_id = "action", lifecycle_id = "registration_type", resource_id = "resource", timestamp = "timestamp")
2条答案
按热度按时间rmbxnbpk1#
将
tibble
(因为数据在tbl_df
中)与sapply
一起使用。由于某些类定义返回多个字符串,因此需要paste
。qxsslcnc2#
您也可以检查
summary.default
以获得一种快速方法: