Я хочу отсортировать списки в зависимости от количества «a» в каждом элементе.
library("purrr")
data1 <- c("apple","appreciate","available","account","adapt")
data2 <- c("tab","banana","cable","tatabox","aaaaaaa")
list1 <- list(data1,data2)
ca <- lapply(list1, function(x) str_count(x, "a"))
t2 <- Map(split, list1, ca)
t3 <- transpose(t2)
> t3
$`1`
$`1`[[1]]
[1] "apple" "account"
$`1`[[2]]
[1] "tab" "cable"
$`2`
$`2`[[1]]
[1] "appreciate" "adapt"
$`2`[[2]]
[1] "tatabox"
$`3`
$`3`[[1]]
[1] "available"
$`3`[[2]]
[1] "banana"
Он потерял «aaaaaaa», который в data2.Как я могу решить эту проблему?
Я нашел решение:
data1 <- c("apple","appreciate","available","account","adapt")
data2 <- c("tab","banana","cable","tatabox","aaaaaaa","aaaaaaaaaaa")
list1 <- list(data1,data2)
ca <- lapply(list1, function(x) str_count(x, "a"))
k11<- flatten(Map(split, list1, ca))
k1<-split(k11, as.integer(names(k11)))