I'm trying to create a function that checks over specific values within my large dataframe. The dataset is imported from SAS into R which seems to create some unique NA values. My solution is to use grep to find these strange values to fix them manually. I want to create a function that simply outputs the values so I can fix them. The function is as follows:
not.numeric <- function(mydata,column) {unique(mydata[grep('[0-9]',mydata$column,invert=TRUE),
c('SeriesID','Reference',column)])}
Easy enough, it searches for non numeric values within the column. For it to properly work, the value for column is surrounded in "". However, when I try to run the function:
not.numeric(df,'Depth')
No values come up and I get a warning message: Unknown or uninitialised column: 'column`. But when I just substitute the values in like this:
unique(df[grep('[0-9]',df$'Depth',invert=TRUE),c('SeriesID','Reference','Depth')])
It works just fine. I want to create a function because I have to check this often and there are 100+ columns to check. Any suggestions why the function doesn't work but the code does?