Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Array slicing
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===1976<!--197?-->: [[S programming language|S]]/[[R programming language|R]]=== Arrays in [[S programming language|S]] and [[R programming language|GNU R]] are always one-based, thus the indices of a new slice will begin with ''one'' for each dimension, regardless of the previous indices. Dimensions with length of ''one'' will be dropped (unless drop = FALSE). Dimension names (where present) will be preserved. <syntaxhighlight lang="rout"> > A <- array(1:60, dim = c(3, 4, 5)) # 3x4x5 three-dimensional or cubic array > A[, , 3] # 3x4 two-dimensional array along first and second dimensions [, 1] [, 2] [, 3] [, 4] [1,] 25 28 31 34 [2,] 26 29 32 35 [3,] 27 30 33 36 > A[, 2:3, 3, drop = FALSE] # 3x2x1 cubic array subset (preserved dimensions) , , 1 [, 1] [, 2] [1,] 28 31 [2,] 29 32 [3,] 30 33 > A[, 2, 3] # single-dimension array along first dimension [1] 28 29 30 > A[1, 2, 3] # single value [1] 28 </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)