0

When I use as.numeric function on chr type data, I get the warning that I mentioned in the title. I tried some recommended ways like x <- gsub(",","",x) then as.numeric(x) . When I used this way, even I didn't get any warning, I see my variable is still chr when I used is.numeric(x)

What else can I do? By the way I am trying to work on this data When I used str() function, I saw some variables are chr while some are num. I didn't understand this distinction too.

Here is my dput of my example data:

dput(RTG[6:10, 1:5] )

structure(list(Date = c("02.11.2020", "02.11.2020", "02.11.2020",  "02.11.2020", "02.11.2020"), Hour = c("5:00", "6:00", "7:00",  "8:00", "9:00"), Total..MWh. = c("25,441.34", "26,408.77", "27,850.92",  "32,157.29", "34,040.87"), Natural.Gas = c("7,933.72", "8,457.68",  "9,506.90", "10,778.43", "11,026.81"), Dammed.Hydro = c("685.28",  "1,055.67", "1,576.70", "4,423.02", "6,139.45")), row.names = 6:10, class = "data.frame")
zx8754
  • 52,746
  • 12
  • 114
  • 209
  • 1
    Can you share some data with us? That will help. Use a command like this: `dput(df[1:10, 1:5] )` You will need to replace df with the name of your dataset; the command will the print a command that replicates the first ten rows and first five columns of your data. Make adjustments as needed. Copy the output and put it in your question. – Ben Nov 27 '20 at 19:06
  • As there are 168 obs. of 18 variables, I can't put the output but when I make adjustment and save it as a new variable, characters are still characters. I add direct PDF link for my data. F.e. I am trying to convert "River" variable into numeric. Because not all variables in data are character, somehow. F.e. "Sun" is numeric. – Ilayda Velioglu Nov 27 '20 at 19:24
  • You don't need to send all your data. Also, you can refer to specific variables, like this: `dput(mtcars[1:10,c("mpg","hp")])` So, just make a `dput` command for the 3 or 4 variables related to you problem, and send just 10 rows. – Ben Nov 27 '20 at 19:27
  • `structure(list(Date = c("02.11.2020", "02.11.2020", "02.11.2020", "02.11.2020", "02.11.2020"), Hour = c("5:00", "6:00", "7:00", "8:00", "9:00"), Total..MWh. = c("25,441.34", "26,408.77", "27,850.92", "32,157.29", "34,040.87"), Natural.Gas = c("7,933.72", "8,457.68", "9,506.90", "10,778.43", "11,026.81"), Dammed.Hydro = c("685.28", "1,055.67", "1,576.70", "4,423.02", "6,139.45")), row.names = 6:10, class = "data.frame")` when I use `dput(RTG[6:10, 1:5] )` . – Ilayda Velioglu Nov 27 '20 at 19:35
  • By the way, I am so sorry if I don't give appropriate answers to your questions, I'm learning R for a month. – Ilayda Velioglu Nov 27 '20 at 19:36
  • This works fine: `RTG$Total..MWh. <- as.numeric(gsub(",", "", RTG$Total..MWh., fixed = TRUE))` – zx8754 Nov 27 '20 at 21:09
  • @zx8754 thank you so much! – Ilayda Velioglu Nov 27 '20 at 21:22
  • Here a little bit more to know: difference between setting decimal places and formatting. https://stackoverflow.com/questions/3443687/formatting-decimal-places-in-r/12135122#12135122 – Ben Nov 27 '20 at 22:16

0 Answers0