0

This dplyr-command usually works just perfect for me, when I want to recode variables. But for some reason it all of the sudden hates the commas, but won't run without them... I have (re)installed both haven and dplyr several times. Any ideas? The first words are Danish names of variables.

OLS <- cses %>% 
transmute(efficacy=iA3029_m,
        uddannelse=iA2003_m,
        køn=iA2002_m-1,
        alder=iA2001_m,
        husindkomst=iA2012_m,
        arbejdsløs=ifelse(iA2007_m==5,1,0),
        sektor=convert_to_NA(as.factor(iA2009_m1),3),
        højre-venstre=convert_to_NA(as.numeric(iA3031_m),95),
        civilstand=ifelse(iA2004_m1==1,1,0),
        religiøs=iA2016_m,
        land-by=iA2022_m,
        polviden,
        aar,
        land) %>% 
Line Bach
  • 11
  • 1
  • The last three items have no right hand side definition (=something). polviden, aar, land – Pierre Lapointe Apr 17 '17 at 17:09
  • 3
    I don't think you can have `-` in dplyr transmute names – jeremycg Apr 17 '17 at 17:10
  • Please make a minimal reproducible example, and give us sample data. – Spacedman Apr 17 '17 at 17:12
  • read [how to provide a reproducible example in r](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – M-- Apr 17 '17 at 17:16
  • @P Lapointe, I wondered the same but my testing shows it as valid. That syntax on `transmute` drops all the original variables and keeps only those explicitly mentioned, which is different from `mutate` which keeps all the originals. – Andrew Lavers Apr 17 '17 at 17:17

1 Answers1

3

You can't have an unqouted minus sign as a named parameter value to a function. This is not allowed

mtcars %>% transmute(disp-cyl=disp-cyl)

But this is allowed (though not recommended)

mtcars %>% transmute("disp-cyl"=disp-cyl)

it's better to use a valid variables names as columns. Perhaps use an underscore

mtcars %>% transmute(disp_cyl=disp-cyl)
MrFlick
  • 195,160
  • 17
  • 277
  • 295