• Register
0 votes

Problem :

I am trying to do some practice on the broom package in R.

I ran the below code :

kclusts <- data.frame(k=1:9) %>% group_by(k) %>% do(fit=kmeans(data.frame, .$k))

But I have received the below error:

Error in as.vector(x, mode) : cannot coerce type 'closure' to vector of type 'any'

I wanted to know whether I am missing something in my above string.

Does anyone have the solution on this issue which I am facing currently?

6 5 3
7,540 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I have gone through your question and I have thoroughly understood it.

I had faced the very similar error in past. So I had done the lot of research on it and eventually found out the solution on it. Please follow the below approach to resolve your issue.

The reason behind you are facing that error can be found in below way:

> typeof(data.frame)
[1] "closure"

You are effectively trying to pass in the method that you use to create data frames, instead of the data frame.

The vignette for the broom has a way to make code like your work:


centers <- data.frame(cluster=factor(1:3), size=c(100, 150, 50), x1=c(5, 0, -3), x2=c(-1, 1, -2))
points <- centers %>% group_by(cluster) %>%
 do(data.frame(x1=rnorm(.$size[1], .$x1[1]),
                  x2=rnorm(.$size[1], .$x2[1])))
ggplot(points, aes(x1, x2, color=cluster)) + geom_point()
points.matrix <- cbind(x1 = points$x1, x2 = points$x2)
# Notice the points.matrix defined above
kclusts <- data.frame(k=1:9) %>% group_by(k) %>% do(kclust=kmeans(points.matrix, .$k))
9 7 4
38,600 points
0 votes


This is a common error we deal with this problem from our SQL server. We need to put correct syntax for a specific data type. If you enter the wrong data type command, it may not work. We added and built functions to the system, debug code and hard coded for any errors occur. This is used to plot graphical dimensions in the web application.


In this case, I think the error you'd see if you did that is around the renderPlot call. Although you're just creating a dynamic UI here, you want to use the UI-compatible functions.

To solve this problem, we have designed measures to research the source code and how to write the source code. We have found the primal solution to this problem. Maybe this answer is not perfect for you, but it will be a solution for you to solve your problem. To download and see the most correct answer, please click the link below to see more secretion

You should avoid putting newlines and even spaces after the function names. Instruct to style guide or here. Code below works perfectly fine.

 As a result we can resolve this simple error for our smooth coding life this may be helpful for anyone



10 6 4
31,120 points

Related questions

0 votes
1 answer 8 views
Problem: I'm doing some practice on broom package in R. I ran the following kclusts <- data.frame(k=1:9) %>% group_by(k) %>% do(fit=kmeans(data.frame, .$k)) I have received the following error Error in as.vector(x, mode) : cannot coerce type 'closure' to vector of type 'any' I was wondering whether I'm missing something in my string. Hope you can help me out.
asked Apr 26 Yeamin 22k points
0 votes
0 answers 66 views
FraudModel = "model{ ##likelihood for (i in 1:n) { Amounts[i]~dnorm(mu[i], phi[i]) mu[i]=betai[1]+betai[2]*Gender[i]+betai[3]*Country[i]+betai[4]*Interest[i]+betai[5]*Time[i]+betai[6]*Purpose[i]+betai[7]*Education[i]+betai[8]*MaritalStatus[i]+betai[9]* ... MaritalStatus, Employment=Employment , Income=Income, Int=Int, Pay=Pay, Pen=Pen, Pre=Pre, w=w, theta=theta, n=n), inits = initval,n.chains = 4)
asked Dec 1, 2020 wisekyn 120 points
0 votes
3 answers 958 views
Problem : I am trying to coerce a list object to type 'double' Please find below my code: a <- structure(list(`X$Days` = c("10", "38", "66", "101", "129", "185", "283", "374")), .Names = "X$Days") Here a is like $`X$Days` [1] ... however the coercing functions are returning me following error: Error: (list) object cannot be coerced to type 'double' Please let me know how can I resolve the issue.
asked Dec 3, 2019 alecxe 7.5k points
0 votes
1 answer 3 views
Problem: I am stuck on an error R "names attribute [1] must be the same length as the vector [0]. " I am not exactly sure how to fix this problem. Any advice would be greatly appreciated .
asked May 4 salim1 60.6k points
0 votes
1 answer 2 views
Problem: I was finally able to work out the code for my scraping. It seemed to be working fine and then all of a sudden when I ran it again, I got the following error message: object of type 'closure' is not subsettable. I am not sure why as I changed nothing in my code. Please advise.
asked Apr 16 muktaa 34.6k points
0 votes
1 answer 31 views
Problem: anyone who know this problem please help? cannot coerce class ""formula"" to a data.frame
asked Mar 26 Rohit kr 17.5k points
0 votes
1 answer 16 views
Problem: While working in r, suddenly I saw an error. The error says: object of type 'closure' is not subsettable.. But I didn&rsquo;t change anything. Please tell me how can I fix this.
asked Apr 16 muktaa 34.6k points
0 votes
1 answer 14 views
Problem: Can anyone tell me the solution of this problem? object of type closure is not subsettable
asked Apr 18 Ifra 37.2k points
0 votes
1 answer 5 views
Problem: Error in <my code> : object of type 'closure' is not subsettable.How can solve this error?
asked Apr 16 Humaira ahmed 50.7k points
0 votes
1 answer 6 views
Problem: Can someone help me with the error message i am getting invalid subscript type closure?
asked Apr 4 Sana8989 8.9k points