Kevin T
Kevin T

Reputation: 43

R data_frame error [Error: could not find function "data_frame"]

I am try to create a data frame with the data_frame method. However, I am getting a error saying "could not find function "data_frame"

> cluster2 <- data_frame(r = rnorm(n, 5, .25), theta = runif(n, 0, 2 * pi),x = enter code herer * cos(theta), y = r * sin(theta), cluster = 2) Error: could not find function "data_frame"

I searched online, I was told that data_frame is a subset of data.frame.

I tried the following and get a different error.

> cluster2 <- data.frame(r = rnorm(n, 5, .25), theta = runif(n, 0, 2 * pi),x = r * cos(theta), y = r * sin(theta), cluster = 2) 

Error in data.frame(r = rnorm(n, 5, 0.25), theta = runif(n, 0, 2 * pi), : object 'r' not found

Any suggestions?

Thanks ahead

Upvotes: 0

Views: 10004

Answers (1)

Will
Will

Reputation: 339

You're using r and theta as arguments in a function that you're calling in the definitions of x and y.

When you're defining the columns r and theta in your dataframe, they are not yet callable objects, but rather a part of the callable object that will be your dataframe.

You need to define r and theta beforehand.

An example of the code required is:

r <- rnorm(n, 5, .25)
theta <- runif(n, 0, 2 * pi)

cluster2 <- data.frame(r = r, 
                       theta = theta,
                       x = r * cos(theta),
                       y = r * sin(theta), 
                       cluster = 2)

rm(r,theta)

View(cluster2)

Upvotes: 1

Related Questions