Sample Dataframe
df<- data.frame(column1=c("row1", "row2", "row3", "row4", "row5", "row6"), column2=c(1,3,4.3,5,6.5,7.8))
check if df$column2
contains decimals. The result should be a TRUE
or FALSE
Try this:
round(df$column2) != df$column2
Since you cannot create a column of internals and doubles, we improperly assume that if the decimal part is 0, then the number is integer.
If you are interested in knowing if the column contains at least one decimal use
any(round(df$column2) != df$column2)
If you are interested in knowing if all the column values are decimal use
all(round(df$column2) != df$column2)
Use the modulus operator.
x%%1==0 will check if the modulus (x mod 1) is 0
x%%1!=0 will check if the modulus (x mod 1) is not 0, which means its value has decimals
This will give you elementwise results:
> df$column2%%1!=0
[1] FALSE FALSE TRUE FALSE TRUE TRUE
for an aggregate on the whole column, call
any(df$column2%%1!=0)
[1] TRUE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With