[R] Creating vectors

JesperHybel jesperhybel at hotmail.com
Thu Aug 12 19:36:43 CEST 2010


You can use following script....I think



#create a vector of random numbers on which to test script

v<-sample(1:3,size=90,replace=TRUE)

#creates two matrixes out of vector v which can be assigned to M to test
script
M2<-matrix(v,ncol=2)
M3<-matrix(v,ncol=3)

M<-   #Assign you're matrix or a testmatrix to M and run script



result<-numeric()
imaks<-length(M[,1])
jmaks<-length(unique(M)[,1])

for (i in 1:imaks){

for (j in 1:jmaks){
if (sum(M[i,]==unique(M)[j,])==length(M[1,]))  {
result[i]<-j
}
}
}

result




## The script uses loops so its not efficient - in other words its slow and
might be too slow for larger matrixes.

BR

Jesper
	
	


-- 
View this message in context: http://r.789695.n4.nabble.com/Creating-vectors-tp2321440p2323090.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list