R: print values greater then

Hi R community!

have the dataframa called df a column named MD within this frame. I want to print every df$MD > 5, so that I can see the outliers. (MD = mahalanobis distance)

for (i in 1:length(df$MD)){
if (df$MD[1:100] > 5){
print(df$MD[1:100]) # value with name

There were 50 or more warnings (use warnings() to see the first 50)

I suggest you filter the original data frame to keep only the rows with MD > 5. In base R you can do

GT5 <- df[df$MD > 5, ]

With the dplyr package, you can do

GT5 <- filter(df, MD > 5)

You can then print the MD column of GT5 or plot its values

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.