我有一个由如下记录组成的数据框。数据帧的典型行 df[1,] 如下所示
84745,"F",70,7,"Single",2,"N",4,9,1,1,3,4,4,"2 day","<120 and <80",0,8,0,1,1,1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1
我想把它转换成一个像下面的 myvar 这样的变量,它是以下类型
myvar = list( list(84745,"F",70,7,"Single",2,"N",4,9,1,1,3,4,4,"2 day","<120 and <80",0,8,0,1,1,1,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1))
我已尝试执行以下操作,但将其转换为列表列表不起作用。
myvar <- as.list(as.list(as.data.frame(t(df[1,]))))
我怎样才能做到这一点?
编辑:我试过 myvar = list(unclass(df[14,])). 但是,由于输出 myvar 的格式略有不同,因此调用失败。
原始代码行的格式
[[1]]
[[1]][[1]]
[1] 21408
[[1]][[2]]
[1] "M"
[[1]][[3]]
[1] 69
[[1]][[4]]
[1] 3
[[1]][[5]]
[1] "Widowed"
myvar 的格式 = list(unclass(df[14,]))
[[1]]
[[1]]$ID
[1] "21408"
[[1]]$GenderCD
[1] "M"
[[1]]$Age
[1] "69"
[[1]]$LOS
[1] "3"
[[1]]$MaritalStatus
[1] "Widowed"