"Why it is setting all row values NA?"
Because the row index is NA. e.g.
> z <- data.frame(a=letters[1:3],b = 1:3); x <- c(TRUE,NA,FALSE)
> z[x,]
a b
1 a 1
NA NA
Change your logical comparison to (using with() to simplify entry):
> dfc[with(dfc, diff > 0 & diff < 100 | is.na(diff)
I have a data
dfc <- read.table( text= 'week v1 v2
w1 11 11
w1 .42
w1 31 32
w2 31 52
w2 41 .
w3 51 82
w2 11 22
w3 11 12
w4 21 202
w1 31 72
w2 71 52', header = TRUE, as.is = TRUE, na.strings=c("",".","NA") )
I want to create this new variable diff = v2
2 matches
Mail list logo