rnorouzian
rnorouzian

Reputation: 7517

How to replace values in a dataset with another values in the same dataset in R?

Suppose I have the following Dataset called D:

D <- read.csv("https://docs.google.com/uc?id=0B5V8AyEFBTmXQ1QwWVZuS3FXOHc&export=download")

In D, whenever the below condition is met, I want D$n1 to be replaced with D$N. How can I do this in BASE R?

if(D$t.type == 0 & is.na(D$n1) & is.na(D$n2))

Upvotes: 1

Views: 59

Answers (1)

BENY
BENY

Reputation: 323226

Is this what you want ?

D$n1[(D$t.type == 0 & is.na(D$n1) & is.na(D$n2))]=D$N[(D$t.type == 0 & is.na(D$n1) & is.na(D$n2))]

Upvotes: 1

Related Questions