I have tried to find an answer to this but I have failed frequently. I have a dataframe with a column of strings. I want to count the number of characters in each entry of the column and replace the string column with the counts.
data[,29]=apply(data[,29],nchar())
Out[2]: Error in match.fun(FUN): argument "FUN" is missing, with no default
Error in match.fun(FUN): argument "FUN" is missing, with no default
There are several problems with the code.
First, apply
operators on a matrix or data.frame
. You probably meant to use sapply
instead.
Second, nchar()
calls nchar
without any argument. You want nchar
— i.e. the function name, without calling it (the calling will happen inside sapply
):
data[, 29] = sapply(data[,29], nchar)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With