0

Hi,

I'm having an issue with data frames where when I run the following code:

test <- data.frame( col <- c(1,2,3,4))

my column name is "col <- c(1,2,3,4)" instead of just "col"

This also happens if I mutate:

test <- test %>% mutate(newcol <- ifelse(1==1, 0,0))

column name is now newcol <- ifelse(1==1, 0,0) instead of just newcol

Is there a way to define the colnames right the first time and not having to rename them.

Thanks

neilfws
  • 32,751
  • 5
  • 50
  • 63
Zee Fer
  • 339
  • 4
  • 14
  • 1
    use `newcol = ifelse(...` instead of `newcol <- ifelse(...` – lefft Dec 05 '17 at 23:42
  • in the first case, `data.frame()` is capturing `col`, but it also becomes an object in the global env. Not so inside of `mutate()` (I believe). – lefft Dec 05 '17 at 23:43

0 Answers0