這裏是我的名單稱爲迪科:獲取列表中列出的元素的長度中的R
dico <- list(list(list(c("dim.", "dimension", "dimensions", "mesures"
), c("45 cm", "45", "45 CM", "0.45m")), list(c("tamano", "volumen",
"dimension", "talla"), c("45 cm", "45", "0.45 M", "45 centimiento"
)), list(c("measures", "dimension", "measurement"), c("45 cm",
"0.45 m", "100 inches", "100 pouces"))), list(list(c("poids",
"poid", "poids net"), c("100 grammes", "100 gr", "100")), list(
c("peso", "carga", "peso especifico"), c("100 gramos", "100g",
"100", "100 g")), list(c("weight", "net wieght", "weight (grammes)"
), c("100 grams", "100", "100 g"))), list(list(c("Batterie oui/non",
"batterie", "présence batterie"), c("Oui", "batterie", "OUI"
)), list(c("bateria", "bateria si or no", "bateria disponible"
), c("si", "bateria furnindo", "1")), list(c("Battery available",
"battery", "battery yes or no"), c("yes", "Y", "Battery given"
))))
視覺上,它看起來像:
[[1]]
[[1]][[1]]
[[1]][[1]][[1]]
[1] "dim." "dimension" "dimensions" "mesures"
[[1]][[1]][[2]]
[1] "45 cm" "45" "45 CM" "0.45m"
[[1]][[2]]
[[1]][[2]][[1]]
[1] "tamano" "volumen" "dimension" "talla"
[[1]][[2]][[2]]
[1] "45 cm" "45" "0.45 M" "45 centimiento"
[[1]][[3]]
[[1]][[3]][[1]]
[1] "measures" "dimension" "measurement"
[[1]][[3]][[2]]
[1] "45 cm" "0.45 m" "100 inches" "100 pouces"
[[2]]
[[2]][[1]]
[[2]][[1]][[1]]
[1] "poids" "poid" "poids net"
[[2]][[1]][[2]]
[1] "100 grammes" "100 gr" "100"
[[2]][[2]]
[[2]][[2]][[1]]
[1] "peso" "carga" "peso especifico"
[[2]][[2]][[2]]
[1] "100 gramos" "100g" "100" "100 g"
[[2]][[3]]
[[2]][[3]][[1]]
[1] "weight" "net wieght" "weight (grammes)"
[[2]][[3]][[2]]
[1] "100 grams" "100" "100 g"
...
我想要得到的所有的所有長度我的名單中的元素。所以,我想的輸出,應該是這樣的:
[[1]]
[[1]][[1]]
[[1]][[1]][[1]]
[1] 3
[[1]][[1]][[2]]
[1] 4
[[1]][[2]]
[[1]][[2]][[1]]
[1] 4
[[1]][[2]][[2]]
[1] 4
[[1]][[3]]
[[1]][[3]][[1]]
[1] 3
[[1]][[3]][[2]]
[1] 4
[[2]]
[[2]][[1]]
[[2]][[1]][[1]]
[1] 3
[[2]][[1]][[2]]
[1] 3
[[2]][[2]]
[[2]][[2]][[1]]
[1] 3
[[2]][[2]][[2]]
[1] 4
[[2]][[3]]
[[2]][[3]][[1]]
[1] 3
[[2]][[3]][[2]]
[1] 3
...
我知道我應該使用lapply,sapply之類的東西,但我被困了幾個小時。你會怎麼做?
您可能需要'lapply(迪科,函數(X)lapply(X,函數(Y)lapply(Y,長度)))'來獲得預期的格式。順便說一句,第一個元素的長度應該是4 [1]「暗淡」。 「尺寸」「尺寸」「尺寸」 – akrun