0

I have a data set N:

[1] 10 13 9 12 5 9 3 13 5 2 4 20 17 1 0 8 5 1 13 10 24 17 7
[24] 6 10 14 16 5 2 32 31 12 7 9 1 2 6 8 9 11 9 1 6 2 2 2
[47] 3 3 41 7 2 15 11 5 3 7 5 12 4 4 7 7 5 10 3 2 10 8 5
[70] 12 14 13 4 11 3 9 16 31 4 10 8 10 3 19 26 11 8 32 8 15 7 9
[93] 51 25 3 7 5 10 16 15

I want to replace '0' with '1'. I've try

M=N
if (N=0) M=N+1

but the result shows no difference with original N, what did I miss? How can I get the result I want?

1 Answers1

0

You could also use replace:

replace(N, N == 0 , 1)

or ifelse:

ifelse(N == 0, 1, N)
Waldi
  • 39,242
  • 6
  • 30
  • 78