Search code examples
rrscript

How to mark all integer values to "-1" in R Studio?


What is equivalent SQL server isnumeric function in R studio. I am trying to migrate one of SQL logic to r studio and i have column where it holds both Char values and Int values, now i want take only int values and update them as -1 in R data.table. Please help me to solve the problem.

I have attached results as image, column "A" values are current values and i am expecting have the values like column B.

enter image description here


Solution

  • Finally i have fix this issue by following below steps.

    1. captured all numeric values to separate data table by using below script CustomDerivedL2AMID <- (subset(DimCombinedEnduser$DRVDEUL2AMID, grepl('^\d+$',DimCombinedEnduser$DRVDEUL2AMID))) library(data.table) HandleDerivedL2AMID <-data.table(CustomDerivedL2AMID)

    2. match the HandleDerivedL2AMID table results with original data table and replaced all values to -1. DCE$DRVDEUL2AMID <- replace(DCE$DRVDEUL2AMID,DCE$DRVDEUL2AMID %in% HandleDerivedL2AMID$CustomDerivedL2AMID,'-1')

    now i see only character values. no more numeric values with data set under DRVDEUL2AMID.