0
bedrooms    bathrooms   sqft_living
3   1   1180
3   2.25    2570
2   1   770
4   3   1960
3   2   1680
4   4.5 5420
3   2.25    1715
3   1.5 1060
3   1   1780
3   2.5 1890

above is the dataset. How to remove/delete the entire row with real number in any attribute? the answer should look like following

bedrooms    bathrooms   sqft_living
5   2   1810
4   3   2950
3   2   1890
4   1   1600
2   1   1200
3   1   1250
AntoniosK
  • 15,991
  • 2
  • 19
  • 32
  • [Selecting only integers from a vector duplicate](https://stackoverflow.com/questions/30476671/selecting-only-integers-from-a-vector); [Subset dataframe by multiple logical conditions of rows to remove](https://stackoverflow.com/questions/6244217/subset-dataframe-by-multiple-logical-conditions-of-rows-to-remove) – pogibas Oct 02 '18 at 10:26
  • i tried using the link but it wasn't really helpful. Can i get a more direct answer. Thanks – Anuja Dalvi Oct 02 '18 at 11:33

1 Answers1

1

I hope this will help. I'll first check every column using lapply to check which elements are equals to themselves after rounding (those are integers). Then I sum the result row-wise using the Reduce. If the output of the Reduce is equal to the number of columns in this df it means that all values were integers:

dt <- read.table(text = "bedrooms    bathrooms   sqft_living
3   1   1180
3   2.25    2570
2   1   770
4   3   1960
3   2   1680
4   4.5 5420
3   2.25    1715
3   1.5 1060
3   1   1780
3   2.5 1890", header = TRUE)

idxs <- Reduce("+", lapply(dt, function(x) round(x) == x)) == ncol(dt)
dt[idxs,]

#  bedrooms bathrooms sqft_living
# 1        3         1        1180
# 3        2         1         770
# 4        4         3        1960
# 5        3         2        1680
# 9        3         1        1780