I have a data frame with data as follows
Col1 Col2 20 NA 25 NA 15 NA NA 10 NA 15
etc. I want to change it as follows
Col1 Col2 20 10 25 10 15 10 15 10 15 15
Basically for forwarding or returning an NA value with the first non-NA value. I tried the option Move the last observation of the factor back and forth in the row group to R , but could not get it to work ... Thanks in advance!
We can do this with help na.locffromzoo
na.locf
zoo
library(zoo) na.locf(na.locf(df1), fromLast = TRUE) # Col1 Col2 #1 20 10 #2 25 10 #3 15 10 #4 15 10 #5 15 15
Source: https://habr.com/ru/post/1672764/More articles:Как создать массив 2-D numpy из 1-D массива? - pythonCross-platform way to get the directory for application data in .NET Core 1.1 - c #Extra spaces appearing in Ansible templates - jinja2Есть ли способ объединить Joi Schemas? - objectCan I remove a Firebase observer with a descriptor using only the root link? - iosElectronic inside Docker with X11 Forwarding - Protocol Not Specified - dockerMacOS: Any way to hide the window title, not toolbar item shortcuts? - cocoarecyclerview add data to the beginning without a mess scroll? - androidMove the last observation of the factor back and forth in the row group in R - rRedShift GROUP BY Constant Column gives inconsistent results - sqlAll Articles