Again, thank you all for the replies (and for the free R lesson!)
You helped me a lot and I very appreciate it.
I will work my self trough the for and apply section of my R manual again..
Thanks,
Bye, inga
--
View this message in context:
http://r.789695.n4.nabble.com/For-loop-with-i-a
a loop) so I suggest you stick with that.
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of ingaschwabe
> Sent: Thursday 18 October 2012 4:51
> To: r-help@r-project.org
> Subject: Re: [R] For loop with i and
There are a bunch of things wrong with your code, from not
understanding subsetting to only returning a single value rather than
a vector of values. I highly recommend that you read the Introduction
to R document that came with your R installation and is readily
available online.
In the meantime:
Dear all,
Thanks for the many replies!
Indeed, the function does not represent my explanation. It should have been:
if (x[i] > 170 && x[i] < 1250 && y[j] > 150 && y[j] < 480)
Sorry, my mistake.
My data looks like this:
head(input[,3:4])
x y
1 701 209
2 685 209
3 566 248
4 562 234
5
- Why are you making a matrix for lookzone if it is ever only one number?
- changing a variable used for iteration is bad practice (input in this case)
though you aren't changing the rows i guess.
- There are too many x and too few y in those ifs.
Plus this is shorter:
test<-apply(input,
If you use ifelse() you don't need the loops at all since ifelse() is
vectorized.
But I don't have any idea why you need two loops: do you really need to
compare all pairs of observations?
Also, the logic in your if statements is not the same as the logic in your
problem description.
Sarah
On T
p-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of ingaschwabe
> Sent: Thursday 18 October 2012 12:36
> To: r-help@r-project.org
> Subject: [R] For loop with i and j and multiple if statements... help!
>
> Dear all!
>
> I'm quite new to R
Dear all!
I'm quite new to R and at this moment a little bit lost in trying to make a
function work with a for loop
that has two variables (i and j) and multiple if statements..
I hope that someone of you could help me. I would very appreciate it!
What do I want to do? I am analysing the data o
8 matches
Mail list logo