-1

Suppose I have data-frame x. It has column "A" and "B".

A        B
a b      a b
c d      c d
e f      e f
a b      a b
a b
a b      a b
a b      a b
a b
a b
a b
a b

I want to display something like this.

A        B
a b      a b
c d      c d
e f      e f
a b      a b
a b      a b
a b      a b
a b      a b
a b      a b
a b      a b 
a b      a b
a b      a b

Basically I want to do filter on x.A for value "a b", so that I can get exact same value on x.B. For column B I have only "a b" and " " values for that. I want to convert " " to "a b" in B column.

I have tried using gsub, sub, filter with regex but after cleaning data if I export this .csv file in excel I am not getting correct output what I want.

camille
  • 15,634
  • 17
  • 33
  • 53

1 Answers1

0

It seems you want to check whether column B has any value. If yes, keep this, if not, put the value of column A there, you can use ifelse:

df$B <- ifelse(df$B == "", df$A, df$B)
Sven
  • 1,165
  • 1
  • 4
  • 14