语境
我正在使用 XLConnect 从电子表格中获取一堆 Excel 命名范围。执行此操作时,XLConnect 会返回一个 data.frames 列表,即使命名范围是单个单元格也是如此。
所以我有一个像这样的数据框列表,每个包含单行和单列,其值如下Mike.Snow - 25/02/2013 2:44:00 PM
:
data <- structure(list(BW_SPUserNameTime = structure(list(Col1 = "Mike.Snow - 25/02/2013 2:44:00 PM"), .Names = "Col1", row.names = c(NA,
-1L), class = "data.frame"), UserNameDateAMCars = structure(list(
Col1 = "John.Doe - 25/02/2013 10:40:00 AM"), .Names = "Col1", row.names = c(NA,
-1L), class = "data.frame"), UserNameDateMJCars = structure(list(
Col1 = "John.Doe - 25/02/2013 10:39:00 AM"), .Names = "Col1", row.names = c(NA,
-1L), class = "data.frame"), UserNameDateOtherCD2CTrains = structure(list(
Col1 = "John.Doe - 25/02/2013 10:36:00 AM"), .Names = "Col1", row.names = c(NA,
-1L), class = "data.frame"), UserNameDateSAP = structure(list(
Col1 = "John.Doe - 25/02/2013 10:34:00 AM"), .Names = "Col1", row.names = c(NA,
-1L), class = "data.frame"), UserNameDateTrainsMineToPort = structure(list(
Col1 = "John.Doe - 25/02/2013 10:38:00 AM"), .Names = "Col1", row.names = c(NA,
-1L), class = "data.frame"), UserNameDateWACLATrains = structure(list(
Col1 = "John.Doe - 25/02/2013 10:36:00 AM"), .Names = "Col1", row.names = c(NA,
-1L), class = "data.frame"), UserNameDateYACLATrains = structure(list(
Col1 = "John.Doe - 25/02/2013 10:36:00 AM"), .Names = "Col1", row.names = c(NA,
-1L), class = "data.frame")), .Names = c("BW_SPUserNameTime",
"UserNameDateAMCars", "UserNameDateMJCars", "UserNameDateOtherCD2CTrains",
"UserNameDateSAP", "UserNameDateTrainsMineToPort", "UserNameDateWACLATrains",
"UserNameDateYACLATrains"))
问题
我如何把它变成一个list of lists
?(具有以下属性)
- 内部列表是一个命名列表,其中
Mike.Snow - 25/02/2013 2:44:00 PM
instrsplit
和Mike.Snow
,2013-02-25 14:44:00
名称类似于User
andTime
。 - 日期部分属于 POSIXlt 类
换句话说,结果应该是这样的......
> data.list <- list(BW_SPUserNameTime = list(
+ User = c("Mike.Snow"),
+ Time = as.POSIXlt("2013-02-25 14:44:00")),
+ UserNameDateAMCars = list(
+ User = c("John.Doe") ,
+ Time = as.POSIXlt("2013-02-25 10:40:00"))
+ )
> data.list
$BW_SPUserNameTime
$BW_SPUserNameTime$User
[1] "Mike.Snow"
$BW_SPUserNameTime$Time
[1] "2013-02-25 14:44:00"
$UserNameDateAMCars
$UserNameDateAMCars$User
[1] "John.Doe"
$UserNameDateAMCars$Time
[1] "2013-02-25 10:40:00"
> sapply(data.list[[1]], class)
$User
[1] "character"
$Time
[1] "POSIXlt" "POSIXt"