[R] assign a cluster based on a variable

Dominik P.H. Kalisch dominik at kalisch.biz
Tue Jun 7 16:24:59 CEST 2011


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?

Thanks for your help.
Dominik



More information about the R-help mailing list