Replacing values across a dataset

Hi,
I have a dataset for monitoring teachers. We have some goals to be fulfilled, hence score is given for each goal according to performance. In the sample I have given below scoring is 1 or 0.5 or -1.
But I want the scores to be replaced as follows:
-1 to 0, 0.5 to 0.
1 will remain as 1.
How can I achieve this?

library(tidyverse)
library(janitor)
#> 
#> Attaching package: 'janitor'
#> The following objects are masked from 'package:stats':
#> 
#>     chisq.test, fisher.test
data<-tibble::tribble(
  ~instructor, ~teacher, ~goal1, ~comments, ~goal2, ~comments, ~goal3, ~comments, ~goal4, ~comments,
          "A",      "P",     -1,    "ACCA",    0.5,    "GSJD",      1,    "RGTH",      1,        NA,
          "B",      "Q",    1.5,   "CGSJJ",    0.5,    "NNDK",      1,   "QWERT",      1,        NA,
          "C",      "R",     -1,     "NSH",      1,    "SMSF",      1,    "CRFT",    0.5,        NA,
          "D",      "S",      1,        NA,     -1,        NA,    0.5,   "SSSSA",    0.5,        NA,
          "E",      "T",      1,        NA,    0.5,        NA,    0.5,        NA,     -1,        NA,
          "F",      "U",    0.5,    "SBHF",    0.5,   "DNJAD",     -1,        NA,     -1,        NA,
          "G",      "V",     -1,    "DHFG",      1,    "DFHY",     -1,    "DFHU",    0.5,        NA,
          "H",      "W",    0.5,        NA,      1,        NA,    0.5,        NA,      1,        NA,
          "I",      "X",     -1,    "DHFG",     -1,        NA,     -1,        NA,      1,        NA,
          "J",      "Y",     -1,   "SAYHT",     -1,    "SRGO",      1,   "SRTUU",    0.5,        NA
  )
Created on 2022-09-20 by the reprex package (v2.0.1)

Here is one method. Notice I changed the column names so there are not duplicate names.
There was one gaol1 value of 1.5, which I assume was an entry error.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
data<-tibble::tribble(
  ~instructor, ~teacher, ~goal1, ~comments1, ~goal2, ~comments2, ~goal3, ~comments3, ~goal4, ~comments4,
  "A",      "P",     -1,    "ACCA",    0.5,    "GSJD",      1,    "RGTH",      1,        NA,
  "B",      "Q",    1.5,   "CGSJJ",    0.5,    "NNDK",      1,   "QWERT",      1,        NA,
  "C",      "R",     -1,     "NSH",      1,    "SMSF",      1,    "CRFT",    0.5,        NA,
  "D",      "S",      1,        NA,     -1,        NA,    0.5,   "SSSSA",    0.5,        NA,
  "E",      "T",      1,        NA,    0.5,        NA,    0.5,        NA,     -1,        NA,
  "F",      "U",    0.5,    "SBHF",    0.5,   "DNJAD",     -1,        NA,     -1,        NA,
  "G",      "V",     -1,    "DHFG",      1,    "DFHY",     -1,    "DFHU",    0.5,        NA,
  "H",      "W",    0.5,        NA,      1,        NA,    0.5,        NA,      1,        NA,
  "I",      "X",     -1,    "DHFG",     -1,        NA,     -1,        NA,      1,        NA,
  "J",      "Y",     -1,   "SAYHT",     -1,    "SRGO",      1,   "SRTUU",    0.5,        NA
)
data <- data |> mutate(across(.cols = starts_with("goal"),.fns = ~ifelse(.x==1,1,0)))
data
#> # A tibble: 10 × 10
#>    instructor teacher goal1 comments1 goal2 commen…¹ goal3 comme…² goal4 comme…³
#>    <chr>      <chr>   <dbl> <chr>     <dbl> <chr>    <dbl> <chr>   <dbl> <lgl>  
#>  1 A          P           0 ACCA          0 GSJD         1 RGTH        1 NA     
#>  2 B          Q           0 CGSJJ         0 NNDK         1 QWERT       1 NA     
#>  3 C          R           0 NSH           1 SMSF         1 CRFT        0 NA     
#>  4 D          S           1 <NA>          0 <NA>         0 SSSSA       0 NA     
#>  5 E          T           1 <NA>          0 <NA>         0 <NA>        0 NA     
#>  6 F          U           0 SBHF          0 DNJAD        0 <NA>        0 NA     
#>  7 G          V           0 DHFG          1 DFHY         0 DFHU        0 NA     
#>  8 H          W           0 <NA>          1 <NA>         0 <NA>        1 NA     
#>  9 I          X           0 DHFG          0 <NA>         0 <NA>        1 NA     
#> 10 J          Y           0 SAYHT         0 SRGO         1 SRTUU       0 NA     
#> # … with abbreviated variable names ¹​comments2, ²​comments3, ³​comments4

Created on 2022-09-20 with reprex v2.0.2

Thank you very much. yes that was a typo error.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.