Reputation: 31
I have one dataframe having two below columns("Name" & "Code").I would like to remove the rows which has numeric values in R. Please help me in this.
Name Code
Sam SDFCVH
Julia KALMN
Hari 123456
Merry 432168
Jazz AWEQRY
Martin 410000
Upvotes: 0
Views: 77
Reputation: 887118
We can use grep
to create a logical index by matching zero or more digits ([0-9]+
) from start (^
) to end ($
), negate (!
) and subset
the rows
subset(df, !grepl("^[0-9]+$", Code))
Or convert the 'Code' to numeric
and all the non-numeric elements will become NA
, check for those elements with is.na
and subset
subset(df, is.na(as.numeric(Code)))
Upvotes: 1