[R] Cleaning data
Jim Lemon
drjimlemon at gmail.com
Wed Sep 27 00:13:23 CEST 2017
Hi Bayan,
Your question seems to imply that the "age" column contains floating
point numbers, e.g.
df
height weight age
170 72 21.5
...
If this is so, you will only find an integer in diff(age) if two
adjacent numbers happen to have the same decimal fraction _and_ the
subtraction does not produce a very small decimal remainder due to one
or both of the numbers being unable to be represented exactly in
binary notation as Eric pointed out. This seems an unusual criterion
for discarding values. Perhaps if you explain why an integer result is
undesirable it would help. It can be done:
badrows<-which(is.integer(diff(df$age)))
df<-df[-badrows,]
OR
df<-df[badrows+1,]
if you want to delete the second rather than the first age.
Jim
On Tue, Sep 26, 2017 at 7:50 PM, bayan sardini <sardinibayan at gmail.com> wrote:
> Hi
>
> I want to clean my data frame, based on the age column, whereas i want to delete the rows that the difference between its elements (i+1)-i= integer. i used
>
> a <- diff(df$age)
> for(i in a){if(is.integer(a) == true){df <- df[-a,]
> }}
>
> but, it doesn’t work, any ideas
>
> Thanks in advance
> Bayan
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list