我想創建一個函式,將輸入的引數解釋為一個字符向量,然后將其作為串列的名稱應用。就像這樣:
list_with_names<-function(. ...){.
b<-list(...)
names(b)< -c(as. 字符(替換(. ...)))。
return(b)
}。
也試過這樣做:
list_with_names<-function(/span>. ...){.
b<-c(...)
x1<-0
for (a in b) {
x1<-x1 1
a[x1]<-c(作為。 字符(替換(. ...)))。
}
names(b)< -c(a)
return(b)。
}。
然而,它只是讀取第一個引數。
uj5u.com熱心網友回復:
考慮使用dplyr::lst
list_with_names<-function(. ...){
dplyr::lst(...)
}。
并測驗為
list_with_names("hello"。 "hello")
$`"hello"`。
[1] "hello"/span>
$`"hello"`。
[1] "Hello"
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/322174.html
標籤:
下一篇:在r中過濾和選擇資料集
