ifelse in 'r' returns NA value -


i have 2 data frames, , want match contents of 1 other, using following function:

t <- read.csv("f:/m.tech/semester4/thesis/code/book1.csv") s <- read.csv("f:/m.tech/semester4/thesis/code/a4.csv") x <- nrow(s) y <- nrow(t) for(i in 1:x)     for(j in 1:y)         ifelse (match(s[i,2], t[j,1]), s[i,9] <- t[j,2] , s[i,9] <- 0) 

for code, when contents match works fine. else part returns na. how can assign 0 places there no match. getting result as:

# word  count   word    tf score    word robability log values  tfxidf score keyword probability # yemen 380 yemen   1   0.053938964 2.919902172 2.919902172 na # strikes   116 strikes 0.305263158 0.016465578 4.106483233 1.25355804  0.5 # deadly    105 deadly  0.276315789 0.014904187 4.206113074 1.162215455 0.7 # new   88  new 0.231578947 0.012491128 4.38273661  1.014949531 na 

instead of na. want store 0 there.

issue 1: ifelse returns 1 of 2 values, depending on test condition. it's not flow control function executes code snippet 1 or code snippet 2 based on condition.

this right:

my_var <- ifelse(thing_to_test, value_if_true, value_if_false) 

this wrong, , doesn't make sense in r

ifelse(thing_to_test, my_var <- value_if_true, my_var <- value_if_false) 

issue 2: make sure thing_to_test logical expression.

putting things together, can see should follow instruction left richard scriven comment above


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -