简体   繁体   English

R data_frame错误[错误:找不到函数“ data_frame”]

[英]R data_frame error [Error: could not find function “data_frame”]

I am try to create a data frame with the data_frame method. 我尝试使用data_frame方法创建一个数据框。 However, I am getting a error saying "could not find function "data_frame" 但是,我收到一条错误消息,提示“找不到函数“ 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. 我在网上搜索时,被告知data_frame是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 提前谢谢

You're using r and theta as arguments in a function that you're calling in the definitions of x and y. 您正在x和y的定义中调用的函数中使用r和theta作为参数。

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. 当您在数据框中定义列r和theta时,它们还不是可调用对象,而是可调用对象的一部分,它将成为您的数据框。

You need to define r and theta beforehand. 您需要预先定义r和theta。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM