0
選擇不到一元我有特徵向量的列表,看起來像這樣:功能單獨工作正常,但與應用函數返回錯誤:試圖在get1index
[[1]]
[1] "medical" "center" "name
[7] "laboratory" "medicine" "william"
[13] "laboratories" "2431" "highway"
...
[680]
...
[[100]]
..
[590]
列表中的每個成員所代表的患者和每個成員的角色矢量是他們的標記化醫療報告。我挖掘列表某些參數的每個成員,並正在使用下面的代碼可以這樣做:
此函數使用單字符矢量對象時,它的工作很大。例如:
>f(P1, "histology results", upto = "diagnosed by"))
[1] highly differentiated, stage 4 out of 4
其中P1是標記化單詞的字符對象。
但是,使用列表和使用lapply函數,我得到一個錯誤。
> lapply(list, f, list[[i]], "histology results", upto = "diagnosed by")
Error in list[[i]] :
attempt to select less than one element in get1index
當我運行選擇列表的單個成員的函數時,它對每個成員都正常工作,沒有錯誤拋出。僅舉一例:
> f(list[[2]], "histology results", upto = "diagnosed by")
[1] "mildly differentiated stage 1 of 4"
我在做什麼錯?
這太神奇了!謝謝!雖然我仍然不太瞭解這個概念。 : -/ – MeeraWhy
如果您熟悉for循環,則類似於:for(i in 1:length(list){f(list [[i]],「組織學結果」,upto =「由...診斷」) (1:length(list),function(i)print(i))','lapply(1:length(list),function(i)list) [i]]。 – Djork
你也可以嘗試'lapply(list,function(i)print(i)',then'lapply(list,function(i)f(i,「histology results」,upto =由「))診斷 – Djork