I am a complete beginner in R. I installed R couple of days ago to complete my course assignment. One of the instructions was that I have to change the data format from wide to long format. The data was a time series data on Remittance inflows from 1972-2021 in Bangladesh. I had the years on the rows and amount of remittance from different countries in columns. I wrote the following code to change the data format to long format:
library(reshape2)
bd_remit_long <- melt(bd_remit,
id.vars = c("Saudi_Arabia", "U.A.E", "U.K", "Kuwait",
"U.S.A", "Libya", "Qatar", "Oman", "Singapore",
"Germany", "Bahrain", "Iran", "Japan"
"Malaysia", "Australia", "Italy", "South_Korea"
"Hong_Kong","Other_Countries", "Total"))
the country names mentioned here are in the columns in the initial data. After running the code my R console is showing: "Error: unexpected string constant in: " "Germany", "Bahrain", "Iran", "Japan" "Malaysia"" I have went back to check my Excel file to see if there were any string values in the observations but couldn't find any. I have multiple missing values in several country observations which are denoted by "...". So to change those missing values to 'NA', I ran this code:
unique(bd_remit$Japan)
bd_remit %>%
select(Japan,Malaysia,Australia,Italy,South_Korea,Hong_Kong)%>%
mutate(Japan = na_if (Japan, "..."))%>%
mutate(Malaysia = na_if (Malaysia, "..."))%>%
mutate(Australia = na_if (Australia, "..."))%>%
mutate(Italy = na_if (Italy, "..."))%>%
mutate(South_Korea = na_if (South_Korea, "..."))%>%
mutate(Hong_Kong = na_if (Hong_Kong, "..."))%>%
(I have installed all the necessary packages to run these commands) But the "..." values did not change into "NA" values either. Now I am completely stuck and I don't know what to do. I really need to change the wide data into long data. Pls help me with your valuable suggestions