给定第一个辅音,元音,最终辅音的列表,我正在创建无意义的单词:
initial_consonants <- c("r", "w", "h", "sp", "st", "sk")
vowels <- c("i", "u", "I", "U", "E", "V", "@")
final_consonants <- c("f", "ts", "rS", "rv", "rl", "Dz", "lts", "bz")
鉴于这组首辅音、元音和尾辅音,我想得到所有可能的 (6*7*8 = 336) 无意义词。我为此创建了这个函数:
create_CVC_words <- function(initial_consonant, vowel, final_consonant){
paste(initial_consonant, vowel, final_consonant, sep = "") -> CVC_word
}
但我不知道如何应用它以便将所有三个维度都考虑在内。outer() 给了我第一个辅音和元音的组合,最后辅音变化:
outer(initial_consonants, vowels, final_consonants, FUN = create_CVC_words) -> table
table
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] "rif" "rults" "rIrl" "rUrS" "rEf" "rVlts" "r@rl"
[2,] "wits" "wubz" "wIDz" "wUrv" "wEts" "wVbz" "w@Dz"
[3,] "hirS" "huf" "hIlts" "hUrl" "hErS" "hVf" "h@lts"
[4,] "spirv" "sputs" "spIbz" "spUDz" "spErv" "spVts" "sp@bz"
[5,] "stirl" "sturS" "stIf" "stUlts" "stErl" "stVrS" "st@f"
[6,] "skiDz" "skurv" "skIts" "skUbz" "skEDz" "skVrv" "sk@ts"
但我需要的是拥有所有可能的组合,即:
rif rits rirS rirv rirl riDz rilits ribz
ruf ruts rurS ...
.
.
.
wif wits ...
我如何使用/调整我的功能来做到这一点?我还需要对较大的无意义词执行此操作,即双音节 CVCVC,因此我需要能够考虑的维度数不限于三个。
编辑:刚刚看到关于如何让 outer() 在这里取 n 维的一般问题:如何将外部推广到 n 维? 但无法为我的问题实施那里给出的解决方案。