Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in match.fun(FUN)

Tags:

r

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
like image 275
mlanier Avatar asked Jun 08 '16 13:06

mlanier


1 Answers

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)
like image 143
Konrad Rudolph Avatar answered Sep 30 '22 15:09

Konrad Rudolph