find the length of an array in r

To find the length of an array in R, you can use the length() function. The length() function returns a scalar integer value representing the number of elements in an array. Here's an example:

main.r
# create an array
my_array <- array(data = c(1, 2, 3, 4, 5, 6), dim = c(2, 3))

# find the length of the array
array_length <- length(my_array)

# print the length of the array
print(array_length)
197 chars
9 lines

This will output:

main.r
[1] 6
6 chars
2 lines

In this example, the my_array array contains 6 elements and has 2 rows and 3 columns. The length() function returns 6, which is the number of elements in the array.

related categories

gistlibby LogSnag