I am trying to write a function that returns all the observations in a specified data frame and column that have a number of letters < 5. For example if an observation was dogs
it would be returned, but if another observation was store
it would not be returned.
This is the code I have written:
count_length <- function(dataset, column_named){
for (i in dataset$column_named)
if (nchar(dataset$column_named[i] < 5)){
paste("problem with ",i)
}
}
count_length(dataset = df,
column_named = pets)
The following error is returning:
Warning message:
Unknown or uninitialised column: `column_named`.
Does anyone know how to fix this and why it is happening? Is it related to the use of $
I wonder?