Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill missing values from other variable?

Tags:

r

dataset

My data set is composed as below.

x    y 
0     
0    0
2    2
     2
     4
2
7    7

I want to merge x and y variable like this

x  
0     
0  
2  
2
4
2
7

That is, I want to fill x variable values with y variable values if x are missing. If there is no missing in both x and y variables two values are always same.

like image 897
Boram Lim Avatar asked Dec 30 '25 13:12

Boram Lim


1 Answers

Another variant

x = ifelse(is.na(x), y,x)
like image 136
Ron Harlev Avatar answered Jan 01 '26 03:01

Ron Harlev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!