create a table that counts the number of times each integer from 1 to 100 appears in an array, a row for every integer from 1 to 100 in r

# Create an array of random integers
set.seed(123)
arr <- sample(1:100, 1000, replace = TRUE)

# Create a table that counts the occurrences of each integer from 1 to 100
table_result <- table(arr)
# Fill in any missing values with 0
table_result <- table_result[match(1:100, names(table_result))]
table_result
310 chars
10 lines

related categories

gistlibby LogSnag