Krypt
Krypt

Reputation: 421

Identify all elements with specific number of decimal places in R

I want to identify all elements with exactly 2 decimal places but i have no idea how to handle that problem...

Example:

x<-data.frame(col1=c("A","B","C"),
              col2=c("1.32","1.235","1.22"))

As a result i only would like to have the corresponding elements from col1, in this case: A C

Upvotes: 3

Views: 80

Answers (1)

akrun
akrun

Reputation: 887691

We can use grep

x$col1[grep('\\..{2}$', x$col2)]
#[1] A C
#Levels: A B C

Upvotes: 4

Related Questions