What is the fastest way in R to compute a recursive sequence defined as
x[1] <- x1 x[n] <- f(x[n-1])
I assume that the eigenvector x is pre-distributed. Is there a smarter way than just looping?
Option: extend it to vectors:
x[,1] <- x1 x[,n] <- f(x[,n-1])
, "", , , , "". , . " " . , , : .
, . , . . , . Etc. . . S-Plus.
;)
, , ? , O (1), , O (n), .
x $y < - f (z) x , , x - . , , R , [[<- . , :
[[<-
x[[1]] <- x1 for (m in seq(2, n)) x[[m]] <- f(x[[m-1]])
, n-1 for, , , , . while, . (lapply ..) ...
( , , , , .)
. Chambers (2008). . . 473-474.
You can write it in C / C ++ / Fortran and use the convenient built-in package to solve compilation, linking and loading for you.
Of course, your function f()can be a real limitation if you want to remain a function of R. Rcpp has an example of a callback from-C ++ - to-R, but this requires a bit more work than just using inline.
f()
Source: https://habr.com/ru/post/1718567/More articles:How to create a low-frequency version of a signal in Matlab? - mathIs the concept of abstraction relevant for tables in MySQL? If so, how can I do this? - oopКак использовать транзакции в DotNetNuke? - transactionsAnt exec shell script - loses environment - shellFailed to build with Qt on Snow Leopard - qtJ2ME, like Sprite on Android - androidShould WCF mex endpoint types match the service endpoint type? - wcfmod_rewrite: if / else type RewriteRule - wordpressWhat is the most suitable construct for an object whose database key consists of several columns? - designMS SQL Server, multiple insertion - sqlAll Articles