• Register
0 votes
499 views

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

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:

 

library(dplyr)
set.seed(2019)
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])))
library(ggplot2)
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

Solution:

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.

Reason:

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 441 views
441 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 145 views
145 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
0 votes
2 answers 839 views
839 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 432 views
432 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