• Register
1 vote
1.7k 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

Please log in or register to answer this question.

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 1
5,680 points

Related questions

0 votes
1 answer 19 views
19 views
Problem: Can someone PLEASE help me figure out why I can't create a legend in R? I have been trying for DAYS. Googling and watching videos. And I KNOW this code works for other people, but not for me. I am using a CSV file. Cannot use TXT file, it won't import correctly. (I have a Mac OS) It keeps ... 45 5.5 1 M2E 42 5.25 2 M2W 25 1.5 2 M3E 20 2.25 2 M3W 43 8.75 2 M4E 35 1.25 1 M4W 30 0.5 1
asked Apr 26 Moumita Bhowmick 12.9k points
0 votes
1 answer 98 views
98 views
Problem: error in sort(y) : argument "y" is missing, with no default.
asked Feb 16 charles mathews 5.5k points
0 votes
1 answer 80 views
0 votes
1 answer 848 views
1 vote
2 answers 1.1K views
1.1K 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, 2020 morrisBson 3.2k points
0 votes
1 answer 16 views
16 views
Problem: I have a list of dataframes that all have identical numbers of columns (and rows). I want to bind them using purrr::map_df. I try map_df(my_list) and get Error in as_mapper(.f, ...) : argument ".f" is missing, with no default I'm not sure what's wrong with my list. It looks good to me (each dataframe has a unique name).
asked May 1 anika11 32.2k points
0 votes
1 answer 2.8K views
2.8K 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 38 views
38 views
Problem: i don&rsquo;t understand about this problem please help? error in aperm.default(map, c(2, 1, 3)) : invalid first argument, must be an array
asked Apr 1 Rohit kr 17.5k points
0 votes
1 answer 885 views
885 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, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 231 views
231 views
Problem : My R code is giving me following error promise already under evaluation: recursive default argument reference or earlier problems?
asked Nov 18, 2019 peterlaw 6.9k points