I am trying to use ifelse to populate a new column in a data frame. 
I want to extract the last digits of a character string in a column if this is longer than 3. if the charachter string is shorter I just want it to give -1...

I already figured out how to extract the last characters of the string if the string is longer than 3 characters. 

```

x<- c("ABCD1", "ABCD2", "ABCD3", "ABCD4", "BC5", "BC6", "BC7")
y<-NULL
dat<-cbind(x,y)

ifelse (nchar(x>3), y=substr(x, 5,5), y=-1)

dat<-cbind(x,y)
view(dat)

```

when I run this, I get the next error

```
  Error in ifelse(nchar(x > 3), y = substr(x, 4, 5), y = substr(x, 3)) : 
   formal argument "yes" matched by multiple actual arguments`

```

What I want is that vector "y" gets the numbers 1,2,3,4,-1,-1,-1
so I can bind both columns latter. If you have a better way of doing this I would appreciate it.