I am working on a project in R that requires me to change a bunch of different currencies to USD. I started by separating the numeric value from the associated currency and placing them in two new columns by using the following code:
```
#Extract numeric values from budget
dataframe$BudgetNum <- as.numeric(str_extract(dataframe$budget, "[0-9]+"))
#Extract character (currency) values from budget
dataframe$BudgetCurrency <- str_extract(dataframe$budget, "[aA-zZ]+")
```
I am a little confused now on how I can convert the different currencies to USD. I tried creating a function with a if statement and then run the function in sapply() but it crashed my R:
convertCurrency <- function(currencyVal){
if(!is.na(dataframe$BudgetCurrency == 'INR')){
BudgetNum = merge.movies.filter$BudgetNum*0.014
return(BudgetNum)
}
}
**The 0.014 is the INR-USD rate
The supply() call is as follows:
z <- sapply(dataframe$BudgetCurrency, convertCurrency)
A few lines of my data are:
imdb_title budget BudgetNum BudgetCurrency
tt000009 $2500 2500 *NA*
tt0000011 ITL60000 600000 ITL
tt0000012 ROL950000 9500000 ROL
tt0000087 INR52000000 52000000 INR
I would appreciate any suggestions/help that anyone could offer! If you need any additional information, please let me know!