File: data_to_numeric.md

package info (click to toggle)
r-cran-datawizard 1.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,300 kB
  • sloc: sh: 13; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 897 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# convert data frame to numeric

    Code
      to_numeric(head(ToothGrowth), dummy_factors = TRUE)
    Output
         len supp.OJ supp.VC dose
      1  4.2       0       1  0.5
      2 11.5       0       1  0.5
      3  7.3       0       1  0.5
      4  5.8       0       1  0.5
      5  6.4       0       1  0.5
      6 10.0       0       1  0.5

---

    Code
      to_numeric(head(ToothGrowth), dummy_factors = FALSE)
    Output
         len supp dose
      1  4.2    2  0.5
      2 11.5    2  0.5
      3  7.3    2  0.5
      4  5.8    2  0.5
      5  6.4    2  0.5
      6 10.0    2  0.5

# convert factor to numeric

    Code
      to_numeric(f, dummy_factors = TRUE)
    Output
         a c i s t
      1  0 0 0 1 0
      2  0 0 0 0 1
      3  1 0 0 0 0
      4  0 0 0 0 1
      5  0 0 1 0 0
      6  0 0 0 1 0
      7  0 0 0 0 1
      8  0 0 1 0 0
      9  0 1 0 0 0
      10 0 0 0 1 0