0
我具有R data.frame對象在數據幀替換值
long <- c(100.25,100.75,100.75,100.75,100.75,100.75,101.25,99.25,99.25,100.25)
vars <- c(1750.8, 1789.7, 1788.1, 1782.8, 1867.3, 1771.3, 1789.9, 1820.6, 1789.1, 1868.9)
varp <- c(1470.714, 1279.862, 1306.740, 1190.296, 1762.874, 1464.975, 1619.855, 1744.476,
1879.743, 2052.337)
df1 <- data.frame(varp,vars,long)
我想更換在所有值瓦爾由NA滿足如下因素條件
(df$long <= 100.75 & df$long >= 100.25)
我試圖
ind<- which(df1$long <= 100.75 & df1$long >= 100.25)
我得到
ind
[1] 1 2 3 4 5 6 10 #
這是上述條件
的真正價值,如果我用
df1$vars[-ind]
[1] 1789.9 1820.6 1789.1 #
我得到的上述條件FLASE值
可能有人請告訴我,我怎麼能代替這些FALSE Index in varars by NA in data.frame?