【发布时间】:2021-07-23 04:29:34
【问题描述】:
我有一个名为data 的数据框,其中包含密码的名称及其值。我还有以下功能:
for(i in 1) {
x <- data$id[i] #id is the column with crypto names (such as "bitcoin")
c1 <- data[data$id == x,5] #5 is the column with values
}
c1 #returns the value of a crypto
对于i in 1,它返回第一个加密的值,对于i in 2,它返回第二个加密的值,依此类推。
我想创建一个函数,通过输入其名称(id)从列表中返回任何加密货币的值,这样它就可以像这样工作:
function("bitcoin")
#Returns the value of a crypto just like c1 above
请让我知道我该怎么做。
【问题讨论】:
标签: r function loops for-loop while-loop