On 07.06.2011 16:24, Dominik P.H. Kalisch wrote:> Hi,
>
> I have two matrices of the following form:
>
> cluster (n=18):
> 12062 1
> 12063 2
> 12064 2
> 12065 3
> 12066 5
>
> KreisSA (n=2304)
> 12062
> 12062
> 12067
> 12065
> 12063
> 12067
>
> I try to assign the cluster[,2] to KreisSAa by the follwoing loop:
>
> n <- nrow(cluster)
> KreisSAa <- numeric()
>
> for(i in 1:n){
> KreisSAa[KreisSA == cluster[i,1]] <- cluster[i,2]
> }
>
> The result is a vector of the length n=4608 where after the entry 2304
> are just NA's
> Has someone an idea what I do wrong?
Since we do not know the structure of your objects, we cannot say
easily. You may want to provide
str(cluster)
and
str(KreisSA)
Anyway: I'd just use merge()
Uwe Ligges
> Thanks for your help.
> Dominik
>
> ______________________________________________
> 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.