search - Searching for row with string value in R data frame -
i new r , have question regarding searching data.frame row.
i have column msg no tmp sensor lat lon alt 1 8d4008b858c381ff633cca3d1b59 0 277102796 13020203 0.00000 0.000000 0.00 2 8d4008b858c37575032db3f2f30e 1 136520046 13020203 51.03620 5.892563 11574.78 3 8d40690958af7480e6c539db2d28 2 902340359 13020203 0.00000 0.000000 0.00 4 8d4008b858c37574612e52e5843d 3 185870171 13020203 51.03243 5.904694 11574.78 5 8d4008b858c375764f2c6ea82b0e 4 615986062 13020203 51.04392 5.867767 11574.78 6 8d4008b858c375749f2e15a34831 5 665795000 13020203 51.03387 5.900040 11574.78 7 8d4008b858c37207a9349cd60077 6 576273468 13020203 51.04486 5.864621 11574.78 8 8d40690958af847ff0c66f60ea8e 7 742755281 13020203 0.00000 0.000000 0.00
the data frame huge (1.5 million value). need check whether there row particular msg. ie ,is there row msg=8d4008b858c37207a9349cd60077(here row 7) . if so, return no (here return 6) value. if there no such value , should notified !
how can efficiently large data frame???
thanks in advance
try
library(data.table)#v1.9.5+ setdt(df1)[msg%chin% '8d4008b858c37207a9349cd60077', no] #[1] 6
or
setdt(df1, key='msg')[.('8d4008b858c37207a9349cd60077'), no] #[1] 6
if checking value not in 'msg' column, return na
setdt(df1, key='msg')[.('xyz'), no] #[1] na
and check na
use is.na
is.na( setdt(df1, key='msg')[.('xyz'), no]) #[1] true
Comments
Post a Comment