Answers for "how to read a vector input in r"

R
0

how to read a vector input in r

elements_ <- c()
# let's say this vector consists of 4 elements
total_dim <- 4
# Using a for loop statement and the sequence function
for (i in seq(total_dim)) {
  elements_[i] <- as.numeric(readline(paste("Enter element",i,": ")))
}
Posted by: Guest on January-28-2022

Browse Popular Code Answers by Language