r - Drop row in a data frame if value has less than 2 decimal places -


in 1 column of data frame, have values longitude. example:

df<-data.frame(long=c(-169.42000,144.80000,7.41139,-63.07000,-62.21000,14.48333,56.99900))

i want keep rows have @ least 3 decimal places (i.e 3 non-zero values after decimal point) , delete others. rows 1,2,4 , 5 deleted df in example above.

so far i've tried usinggrep extract rows want keep:

new.df<-df[-grep("000$",df$long),]

however has deleted rows. ideas? i'm new using grep there may glaring errors i've not picked on!

many thanks!

you have modify regular expression slightly. following 1 select values 3 non-zero numbers after decimal point:

new.df <- df[grep("\\.[1-9][1-9][1-9]", df$long), ] 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -