removing null element from vector

Hi everyone,
I have a little problem, i need to do somithings like this:

B=c()
A=c(1:10)

A and B will be used in a "for cycle", in this cycle B will contain some index refered to a value of A
i need to remove the future value of B from A

A=A[-B]

obviously in the first loop i need B empty, cuz i'll take the value inside the cycle.

But if i use A=A[-B], with empty B the system tell me that the elemente is an invalid operator.
How can i subtract empty element for the first time?

example:
i need to see if the product of all the element of two vector is inside a range.


range=c(30,70)
A=c(1:1000)
K=sample(seq(0,1,0.001))
B=c()

for(i in K){
A=A[-B]
for(j in A){
if (i*j>min(range) & i*j<max(range)) {
B=c(B,which(A==j))
}}}

Error in -B : argomento non valido per l'operatore (invalid argument for the operator)

thank you!

you could test if B is null so as to decide to not omit it from A

if(!is.null(B)) A=A[-B]

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.