3
In the following example:
> str(rhm)
'data.frame': 24 obs. of 4 variables:
$ plant : Factor w/ 1 level "LaR": 1 1 1 1 1 1 1 1 1 1 ...
$ time : int 0 0 0 0 3 3 3 3 7 7 ...
$ Tratamento: Factor w/ 4 levels "T1pH1","T1pH2",..: 1 2 3 4 1 2 3 4 1 2 ...
$ wt : Factor w/ 20 levels "0,0013","0,0017",..: 20 20 20 20 10 16 18 17 12 19 ...
> str(unclass(rhm$wt))
atomic [1:24] 20 20 20 20 10 16 18 17 12 19 ...
- attr(*, "levels")= chr [1:20] "0,0013" "0,0017" "0,0036" "0,0045" ...
When trying to turn the wt variable into number, instead of "0.0013", "0.0017"... appear:
as.numeric(rhm$wt)
[1:24] 20 20 20 20 10 16 18 17 12 19 ...
How to convert wt to numbers?
I tried two suggested ways in forum:
as.numeric(as.character(rhm$wt))
as.numeric(levels(rhm$wt))[rhm$wt]
However occurs the replacement of my data by Nas:
[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
Warning message:
NAs introduced by coercion
How can I transform my data correctly?
Just remembering that option 2, to correct in reading the data, is much more interesting because it solves the problem for all columns at once (if it is the case) and uses fewer characters.
– Molx
Thank you! Solved!
– Juanita Hernández Solano