创建一个R函数,告诉你某个加密货币与另一个加密货币的硬币数量



我正在努力完成r语言的作业。我是计算机语言的新手,请原谅我的无知。

我有一个包含500种加密货币和相关数据的数据集。加密货币的名称在ID栏下,一种加密货币的欧元值在current_price栏下。我需要创建一个新的功能来在加密货币之间转换,有三个输入:我转换的货币,我在该货币中的硬币数量,以及我转换为的货币。

这就是我想到的,它不起作用,每次我更改它时都会出现新的错误。

convert <- function (x,amount,z) {
currency_price <- mdata$current_price
currency_id <- mdata$id
index_currency_id_x <- which( x == currency_id) [[1]]
index_currency_id_z <- which ( z == currency_id) [[1]]
conversion <- currency_price[[index_currency_id_z]] * amount 
return (conversion/currency_price[[index_currency_id_z]])
}

如果我运行每一行代码,我就会收到错误:

Error in which(x == currency_id) : object 'x' not found
Error in which(z == currency_id) : object 'z' not found
Error in currency_price[[index_currency_id_z]] : 
attempt to select less than one element in get1index
Error in currency_price[[index_currency_id_z]] : 
attempt to select less than one element in get1index

这个错误只是意味着您没有向函数提供x和y。应该是convert(x=,amount=,y=)

最新更新