[R] R loop problem

jim holtman jholtman at gmail.com
Thu Aug 4 14:27:06 CEST 2011


A subset of actual data and what you would expect as a result would be
very helpful.   All you say is that p.q are vectors, but it would
appear that they are character vectors, but the content is unknown.
Also will the expression "q[i==p]<-z[i==y]" have the same length on
each side; the vectors appear to be of different lengths -- what
happens if recycling kicks in?  Or it is always a match of length 1"

So a little more definition, and data and example, would help.

On Thu, Aug 4, 2011 at 5:27 AM, testrider <testrider at gmail.com> wrote:
> I have run into a speed issue, and given the size of the problem it feels
> like there should be an easy solution. Here is the problem statement with
> some arbitrary numbers added.
>
> #p,q: vector with length(q)==length(p)==10000 and length(levels(p))==3000
> #y,z: vectors with length(levels(y))=length(y)==length(z)==5000
>
> for (i in levels(p)){
> q[i==p]<-z[i==y]}
>
> At first i used two for loops which was horrible, now i got rid of one but i
> don't know how to lose the second one.
>
>
> PS. I expect the solution to be available through google etc and I have
> searched for a solution but i did not find any usefull websites, probably
> because i cannot pinpoint the best search words.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/R-loop-problem-tp3718103p3718103.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list