• 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
3 answers 768 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
0 answers 36 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
1 answer 569 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
2 answers 1.5K views
Problem : I am facing below error and I am unable to understand the meaning of the error. All my variable names are correct and there are no typing errors. Does anybody faced this issue before any solution on it? My erroneous code : datNewagg <- aggregate (dataNew, by = ... mean) It gives following error : Error in aggregate.data.frame(datNew, by = list("x", "y", : arguments must have same length
asked Dec 6, 2019 alecxe 7.5k points
0 votes
1 answer 866 views
Problem : I am trying to merge data in R but facing following error error in fix.by(by.x, x) : 'by' must specify one or more columns as numbers, names or logical
asked Nov 15, 2019 peterlaw 6.9k points
0 votes
2 answers 2.5K views
Problem : Below is my code which is giving me the error. plot(x,y) yx.lm <- lm(y ~ x) lines(x, predict(yx.lm), col="red") Why am I facing following error? Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet
asked Dec 4, 2019 alecxe 7.5k points
0 votes
1 answer 143 views
0 votes
1 answer 892 views
0 votes
1 answer 387 views
0 votes
2 answers 1.3K views
Problem : I am looking for the function with the parameters such as data name as (mydata), factor as (myfactor) and variable names such as (myvar) to dynamically generate the histograms as I have to use them in lattice. I tried to do as mentioned above but error appears ... of type 'character'. I think the program doesn't know where to look for this myf` string. How should I fix this issue?
asked Dec 23, 2019 alecxe 7.5k points