I got a big data base but for this exercise let's use this one:

```
    c-1    c-2   c-3  c-4  c-5 c-6  
   1-14  14-29  NA    NA   NA  NA
   60-90  CF    CF    CF   CF  CF
    C     1-14  14-29 CF   NA  NA
   60-90  CF    CF    CF   NA  NA

```

What i want is to change all the columns that got a CF in the column immediately before to a HF so it would look like this:

```
   c-1    c-2   c-3  c-4  c-5 c-6  
   1-14  14-29  NA    NA   NA  NA
   60-90  CF    HF    HF   HF  HF
    C     1-14  14-29 CF   NA  NA
   60-90  CF    HF    HF   NA  NA

```

I have tried to do it with an apply like this but it isn't working properly 

```
function_a <- function (x) {ifelse(df[,i]=="CF" & df[,i-1]=="CF", "HF", df[,i])}    
new_df<- as.data.frame(lapply(length(df):1, function_a))

```

Please keep in mind I want to preserve the original value if the previous column is not CF, is there any easy way to do this? on R base?