R Gurus, I am struggling to find an efficient way to split a string into multiple parts given in a vector.
In the following example, I have few cryptocurrencies' pairs from BINANCE exchange. I want to split each pair into two separate parts given in symbol column in top100 data frame.
library(dplyr)
library(jsonlite)
library(RCurl)
top100 <- data.frame(fromJSON(getURL(paste0('https://api.coinmarketcap.com/v1/ticker/?start=0&limit=100'))))
markets <- data.frame(pairs = c("NEOBTC","EOSETH","VENETH","ELFETH","ICXETH","BNBETH","NEOETH",
"TRXETH","QTUMETH","DASHETH","XRPETH" ,"ETHUSDT","LTCUSDT","ADAETH",
"XMRETH","ZECETH","IOTAETH","NEOUSDT","BNBUSDT","XLMBNB","LSKBNB"),
symbol1 = NA,
symbol2 = NA)
markets$symbol1 <- substr(markets$pairs, 1,3) markets$symbol2 <- substr(markets$pairs, 4,6)
markets$symbol1 %in% top100$symbol markets$symbol2 %in% top100$symbol
One naive way do that is to take first three characters of the ticker as symbol1 and last three characters as symbol2, some tickers have more than three characters like DASH.