2
I tried to write a simple command on R
where the program asks 5 numbers for the user (input) and adds each one to a list. The problem is that the array is empty. I’ve tried lists too.
Follow the code below:
a <- c()
for(numero in 1:5){
num <- as.numeric(readline(prompt = 'Numero: '))
append(a,num)
}
print(a)
And if I do not know a priori how much data I will store in the vector? For example, let’s assume that I will filter all averages with size may 15 of a given vector but I don’t know how many are a priori? In this case, the only way I see to store these values greater than 15 is to add them to an array. I don’t know if it’s because I’m more used to Python where it’s common to add elements in lists, but my reasoning is this.
– Guilherme Matos Passarini
This is a very long topic to answer here. If you read English, see chapter 2 of The R Inferno. Take advantage and read chapter 3, because it is also good to avoid loops in R. Well, read the whole book, which is excellent.
– Carlos Eduardo Lagosta