Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 447

Replace NA values with values from cells on the right in R

$
0
0

I have a data frame with sets of NA values between data, like this:

dfDate1 Value1a Value1b Value1c Date2 Value2a Value2b Date3 Value3a Value3b Date4 Value4a Value4b Value4c2015-01-21 negative negative positive 2015-02-27 negative negative 2015-05-23 negative negative 2016-04-07 negative negative positive2015-03-10 negative negative positive NA NA NA NA NA NA 2016-02-11 negative negative positive2015-05-21 positive negative positive NA NA NA NA NA NA 2016-04-18 positive negative positive

And I need try to replace NA values with values from the right if sets of NA begins in some date column. So I would like the following result:

dfDate1 Value1a Value1b Value1c Date2 Value2a Value2b Date3 Value3a Value3b Date4 Value4a Value4b Value4c2015-01-21 negative negative positive 2015-02-27 negative negative 2015-05-23 negative negative 2016-04-07 negative negative positive2015-03-10 negative negative positive 2016-02-11 negative negative positive negative NA NA NA NA NA
2015-05-21 positive negative positive 2016-04-18 positive negative positive negative NA NA NA NA NA

Any suggestion would be very appreciate.


Viewing all articles
Browse latest Browse all 447

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>