Length of vector x

Length of vector x

par Mahnoor Hamid,
Nombre de réponses : 3

Hi,

I am having trouble with setting the length of the vector x to equal n. I tried x <- vector(length=n) and x -> length(x) but I am getting an error saying object 'n' not found. How can I troubleshoot this?


Thanks

En réponse à Mahnoor Hamid

Re: Length of vector x

par Erik Spence,
Why are you trying to set the length of the vector? The length of the vector is whatever it happens to be, it's not something you specify.
En réponse à Erik Spence

Re: Length of vector x

par Mahnoor Hamid,
I was trying to define n because I kept getting the error about object 'n' not found. Now when I am using length(x) <- n, I do get an output but it is not a number (I've gotten NaN, NA, or Inf). How can I fix that?
En réponse à Mahnoor Hamid

Re: Length of vector x

par Erik Spence,
If n is the length of x, why are you defining the length of x to be n? You're doing it backwards.