a*******a 发帖数: 1336 | 1 D是2维矩阵
for (i in 1:n)
{
for (j in 1:n)
{
D[i,j]=f(i, j)
}
}
这样的程序在R里慢得不得了,我用apply(D,1,f())可是不知道f()里怎么写row 和
col index,谢谢各位大侠 | l*********s 发帖数: 5409 | 2 generate a vector of the size n*m, and pass the vector index to your user
defined function f() to construct the data set.
(The rol,col index can be computed from the vector index parameter.)
Then cast the vector into a matrix. | a*******a 发帖数: 1336 | 3 谢谢,1:n*m的vector算index的话只能用整除/取模么?这样岂不也很慢。。
【在 l*********s 的大作中提到】 : generate a vector of the size n*m, and pass the vector index to your user : defined function f() to construct the data set. : (The rol,col index can be computed from the vector index parameter.) : Then cast the vector into a matrix.
| l*********s 发帖数: 5409 | 4 Integer operation is much faster than float operation.
Computers have no concept about matrix and R has to do the memory I/O behind
scene.Thus you are not going to save computation by writing less codes.
【在 a*******a 的大作中提到】 : 谢谢,1:n*m的vector算index的话只能用整除/取模么?这样岂不也很慢。。
| s*****n 发帖数: 2174 | |
|