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 many times
as the maximum number of spaces on each gap; something that may not work
well for large files.

I am trying to solve the new example with base R functions only. I thought
of splitting the first column to multiple lists and use one of the apply
functions, but was not successful.

Would apprecaite some hints on how to go about it.

Thanks as always in advance—EK

The posted data frame from the original posting:
names val
1 Mandy   1
2         2
3 John    2
4         2

My modified data frame:
val <- c(1,2,3,4,5,6,7,8)
nam <- c("mandy","", "John","","","","Zara","")
df1 <- data.frame(nam,val)

    nam val
1 mandy   1
2         2
3  John   3
4         4
5         5
6         6
7  Zara   7
8         8

My code for solving the original data farme
> which(df1$nam=="")
> a <- which(df1$nam=="")
> df1$nam[a] <- df1$nam[a-1]

        [[alternative HTML version deleted]]

R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to