Re: [R] Fill in empty spaces modified

2017-08-09 Thread William Dunlap via R-help
The following, locf2(), does what you want using only base R functions: locf2 <- function(x, initial=NA, IS_BAD = is.na) { # Replace 'bad' values in 'x' with last previous non-bad value. # If no previous non-bad value, replace with 'initial'. stopifnot(is.function(IS_BAD)) good <-

Re: [R] Fill in empty spaces modified

2017-08-09 Thread David Winsemius
> On Aug 9, 2017, at 3:39 PM, Ek Esawi wrote: > > Thank you so much Jim. I forgot to state that i was hoping to get it > without loops if possible. > > library(zoo) > is.na(eedf$nam) <- eedf$nam == "" > eedf$nam <- na.locf(eedf$nam) > eedf nam val 1 mandy 1 2 mandy 2 3 John 3 4 Jo

[R] Fill in empty spaces modified

2017-08-09 Thread Ek Esawi
Thank you so much Jim. I forgot to state that i was hoping to get it without loops if possible. Thanks again, EK [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mai

Re: [R] Fill in empty spaces modified

2017-08-09 Thread Jim Lemon
Hi Ek, As I may have mentioned previously, if you don't mind stepping through the data frame row by row you can do it like this: eedf<-read.table(text="nam,val mandy,1 ,2 John,3 ,4 ,5 ,6 Zara,7 ,8",sep=",",header=TRUE,stringsAsFactors=FALSE) for(row in 1:nrow(eedf)) if(eedf$nam[row] == "") eedf

[R] Fill in empty spaces modified

2017-08-09 Thread Ek Esawi
Hi All— I was looking at a posting from June-17. I managed to solve it. However, when I changed the example in the posting, my solution will work only once at a time which was mentioned by Jim Lemon on his response to the original posting. This means that my solution will have to be repeated as m