0

I'm trying to use ggplot in R to do box plot with jittered data points. The data shown in the environment has length represented by factor instead of numeric. So I want to change it to numeric number so that I can do the plot. I used the following code but it returned NAs introduced by coercion. What should I do now?

um2$length1<-as.numeric(as.character(um2$length))

data data summary

I tried to use as.numeric and as.character, but it does not work

r2evans
  • 141,215
  • 6
  • 77
  • 149
  • Welcome to SO, Baekgogi! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Nov 16 '22 at 04:05
  • `as.numeric(as.character(factor(c("1.25 ", "1.28 "))))` produces no `NA`s. Your question is not reproducible, and even if the images of your data were sufficient (they are not), many people will not transcribe your data from your image to something usable. Please do not post (only) an image of code/data/errors: it breaks screen-readers and it cannot be copied or searched (ref: https://meta.stackoverflow.com/a/285557 and https://xkcd.com/2116/). Please include the code, console output, or data (e.g., `data.frame(...)` or the output from `dput(head(x))`) directly. – r2evans Nov 16 '22 at 04:06
  • Greetings! Usually it is helpful to provide a minimally reproducible dataset for questions here so people can troubleshoot your problems (rather than a screen shot or table). One way of doing this is by using the `dput` function. You can find out how to use it here: https://youtu.be/3EID3P1oisg – Shawn Hemelstrand Nov 16 '22 at 05:33

0 Answers0