这是我的数据集。它是10个数据帧的列表,每个数据帧包含不同的元素。我想要做的是分割每个数据框中的字符对象,使其只显示对象中的数字,而不是字母。因为在这之后我将测试每个数据帧中的数字是偶数还是奇数,所以它可能必须变成整数向量。因此,例如,对于第一个数据帧,它将返回4.对于第二个数据帧,它将返回8.对于第三个,它将返回4 12等等。
$control
[1] "A4"
$control
[1] "G8"
$pq
[1] "A4" "G12"
$docetaxel
[1] "G8"
$docetaxel_b
[1] "A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8"
[21] "B9" "B10" "B11" "B12" "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4"
[41] "D5" "D6" "D7" "D8" "D9" "D10" "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9"
$docetaxel
[1] "E9" "E10" "E11" "E12" "F1" "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10" "F11" "F12" "G1" "G2" "G3" "G4"
[21] "G5" "G6" "G7" "G8" "G9" "G10" "G11" "G12" "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12"
$dactinomycin
[1] "E12"
$cisplatin
[1] "F8"
$cisplatin_b
[1] "A1" "A2" "A3" "A4" "A5" "A6"
$cisplatin
[1] "A6" "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" "B9" "B10" "B11" "B12" "C1"
[21] "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4" "D5" "D6" "D7" "D8" "D9"
[41] "D10" "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "E10" "E11" "E12" "F1" "F2" "F3" "F4" "F5"
[61] "F6" "F7" "F8" "F9" "F10" "F11" "F12" "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G8" "G9" "G10" "G11" "G12" "H1"
[81] "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12"
提前谢谢!
答案 0 :(得分:1)
我认为您的列表不包含数据框,至少不是如图所示。这是一种摆脱角色的方法。这是您数据的一小部分。
lst <- list(control="G8", pq=c("A4", "G12"), docetaxel=c("G8"), docetaxel_b=c("A1", "A2"))
lapply(lst, function(x) as.numeric(gsub("[^0-9]", "", x)))
产生
$control
[1] 8
$pq
[1] 4 12
$docetaxel
[1] 8
$docetaxel_b
[1] 1 2
基本上,我们只是用"[^0-9]"
删除任何不是数字(gsub
)的内容,然后转换为数字。您可以轻松地修改lapply
内的函数来检查值是偶数还是奇数,类似%% 2
,但不知道您想要知道什么(均衡数,存在赔率等) 。),我无法提供进一步的指导。