Skip to content
Snippets Groups Projects
Commit d520dd7e authored by Dainius's avatar Dainius
Browse files

Add an example of a fairly-efficient apply on multidimensional arrays

parent 7a423bb9
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` R
a = array(1:27, dim=c(3,3,3)) # 3D array: x,y,time
```
%% Cell type:code id: tags:
``` R
aq = apply(a, c(1,2), quantile) # Also a 3D array, but for some reason quantile,y,x
```
%% Cell type:code id: tags:
``` R
aperm(aq) # Like t, but for arrays
```
%% Output
1. 1
2. 4
3. 7
4. 2
5. 5
6. 8
7. 3
8. 6
9. 9
10. 5.5
11. 8.5
12. 11.5
13. 6.5
14. 9.5
15. 12.5
16. 7.5
17. 10.5
18. 13.5
19. 10
20. 13
21. 16
22. 11
23. 14
24. 17
25. 12
26. 15
27. 18
28. 14.5
29. 17.5
30. 20.5
31. 15.5
32. 18.5
33. 21.5
34. 16.5
35. 19.5
36. 22.5
37. 19
38. 22
39. 25
40. 20
41. 23
42. 26
43. 21
44. 24
45. 27
\begin{enumerate*}
\item 1
\item 4
\item 7
\item 2
\item 5
\item 8
\item 3
\item 6
\item 9
\item 5.5
\item 8.5
\item 11.5
\item 6.5
\item 9.5
\item 12.5
\item 7.5
\item 10.5
\item 13.5
\item 10
\item 13
\item 16
\item 11
\item 14
\item 17
\item 12
\item 15
\item 18
\item 14.5
\item 17.5
\item 20.5
\item 15.5
\item 18.5
\item 21.5
\item 16.5
\item 19.5
\item 22.5
\item 19
\item 22
\item 25
\item 20
\item 23
\item 26
\item 21
\item 24
\item 27
\end{enumerate*}
%% Cell type:code id: tags:
``` R
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment