• Register
1 vote
526 views

Problem :

Currently I am learning the r programming. I am unable to find the answer to below error but I am unable to do so. Currently I have one dataframe it has a column of strings. My task is to count the exact number of characters present in each entry of a column and then replace a string column with a counts.

Please find below the error for your reference:

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

Can someone guide me in fixing above error?

8 5 2
3,230 points

1 Answer

1 vote

Solution :

I went through your issue and I came to know that you are beginner so I am trying to help you.

I guess there are many problems with your code so you are facing above error.

So you need to first apply operators on your matrix or on your data.frame. I guess you wanted to use the sapply instead.

The next problem is with nchar() calls the nchar without any argument in it. So you must use nchar as the function name and you should avoid calling it  as the calling will happen inside sapply as shown below:

data[, 29] = sapply(data[,29], nchar)
8 4
5,680 points

Related questions

0 votes
1 answer 14 views
1 vote
2 answers 259 views
259 views
Problem : I am very new to R. I am facing a issue while entering CurrentDay. I had previously created it as below : Transaction <- function(PnL, Day)   results <- list(a = PnL, b = Day)  return(results) The above PnL and Day are both numeric values. Day ... /MA  return(MAValue) } Please guide me why am I receiving below error? Error in fun(left, right) : non-numeric argument to binary operator.
asked Apr 14 morrisBson 3.2k points
0 votes
1 answer 1.3K views
1.3K views
Problem : I have been facing below error message and traceback: Error in FUN(X[[i]], ...) : only defined on the data frame with all numeric variables 5 stop("only defined on the data frame with all numeric variables") 4 FUN(X[[i]], ...) 3 lapply(args, ... .numeric(data[good,]) But now I get the different error message back as below : "Error: (list) object cannot be coerced to type 'double'"
asked Dec 16, 2019 alecxe 7.5k points
0 votes
1 answer 135 views
135 views
Problem: I have only the fundamental knowledge related to R. I want to simulate the very basic moving average process in R which is as shown below for your reference: x_t = Z_(t-1)-0.4Z_(t-2)+Z_t. Please find below my code in R: z = rnorm(500, 0, 1) x ... was unable to find the exact solution for my above error. I am looking for some help from R expert if possible to fix my above R related error.
asked Aug 12 Raphael Pacheco 4.9k points