0

I have two variables a and b in my dataset:

 a                                           b
 fd648389-7ebb-4780-b9d1-4d4d5c8656ed        NA
 9b1a0172-056a-49e2-90e0-3b73874862b0        53c9f535-dda5-4e9b-9d0a-8f8f1dc8b1fd

I want to replace variable b with a whenever b has NA

output for b:

b
fd648389-7ebb-4780-b9d1-4d4d5c8656ed 
53c9f535-dda5-4e9b-9d0a-8f8f1dc8b1fd

I tried using it but NA is replaced with 1110 instead of fd648389-7ebb-4780-b9d1-4d4d5c8656ed. Iam not sure from where is 1110 coming from.

Jaap
  • 81,064
  • 34
  • 182
  • 193
suresh
  • 33
  • 5
  • I tried using it but it replace NA is replaced with 1110 instead of fd648389-7ebb-4780-b9d1-4d4d5c8656ed. Iam not sure from where is 1110 coming – suresh May 12 '16 at 16:23
  • That is highly probably because the columns have class factor. You can either read your data with using the parameter `stringsAsFactors=FALSE` or convert the variables to character with `as.character`. – Jaap May 12 '16 at 16:31
  • I tried converting it using as.character but it showing as NA – suresh May 12 '16 at 16:37
  • What is the the class of your `a` and `b` columns? – Jaap May 12 '16 at 16:38
  • for a its factor and for b it shows as character – suresh May 12 '16 at 16:52
  • I change all the varaibles to character and tried using b[i1] <- ifelse(b[i1] == "",a[i1],b[i1]). It ended in NAs are not allowed in subscripted assignments – suresh May 12 '16 at 17:01
  • In that case, changing `a` to character should work. – Jaap May 12 '16 at 17:06

0 Answers0