0

私は R プログラミングに関する講座の講義を練習していました。彼が tapply() 関数を実演する講義の 1 つで、講義で教えられていることをコピーして貼り付けただけですが、構文エラーが発生しました。

x <- c(norm(10),runif(10), rnorm(10,1))
f <- g1(3,10)
tapply(x, f, mean)

結果は次のようになります

tapply(x, f, mean)
1 2 3
0.1144464 0.5163468 1.2463678

しかし、私が得ているのはエラー値です

x <- c(norm(10),runif(10), rnorm(10,1))
Error in norm(10) : 'A' must be a numeric matrix
f <- g1(3,10)
Error: could not find function "g1"
tapply(x, f, mean)
Error in tapply(x, f, mean) : object 'f' not found
4

1 に答える 1

1

You just have some typos in your code:

x <- c(rnorm(10),runif(10), rnorm(10,1))
f <- gl(3,10)
tapply(x,f,mean)

This will give you the output you want.

Your typos are:

g1 should be gl

and

norm should be rnorm

update

No problem. It might be helpful to learn about apropos in R. It's sort of like a search function for functions/objects. Documentation

If you can't remember the name of a function (let's say rnorm) but you can remember the beginning of it (rnor), you can type

apropos("rnor")

which will return

[1] "rnorm"

Then you can type ?rnorm to access the documentation for rnorm.

于 2014-07-24T19:49:57.343 に答える