This already exists:
library(zoo)
na.locf(data.frame(rep("a",4), 1:4,1:4, c(1,NA,NA,NA)))
More Related Contents:
- Reshape three column data frame to matrix (“long” to “wide” format) [duplicate]
- Split a large dataframe into a list of data frames based on common value in column
- Sum rows in data.frame or matrix
- Remove columns from dataframe where ALL values are NA
- R Apply() function on specific dataframe columns
- Apply a function to every row of a matrix or a data frame
- Create dataframe from a matrix
- Change row order in a matrix/dataframe
- apply a function over groups of columns
- rbind data frames based on a common pattern in data frame name
- Dataframe create new column based on other columns
- Calculate row-wise proportions
- Should I use a data.frame or a matrix?
- use multiple columns as variables with sapply
- R memory management / cannot allocate vector of size n Mb
- How to subset matrix to one column, maintain matrix data type, maintain row/column names?
- How to drop columns by name in a data frame
- Detect at least one match between each data frame row and values in vector
- Remove/collapse consecutive duplicate values in sequence
- Converting nested list to dataframe
- Why is `vapply` safer than `sapply`?
- Cartesian product data frame
- Merge Two Lists in R
- Transposing a dataframe maintaining the first column as heading
- Filter data frame rows based on values in vector
- Select rows of a matrix that meet a condition
- Replace values in data frame based on other data frame in R
- Add an image to a table-like output in R
- R how can I calculate difference between rows in a data frame
- Color one point and add an annotation in ggplot2?