[R] get the values of unique ID

Jane Yu jyuzh at yahoo.com
Thu Mar 27 20:09:23 CET 2003

Hi, All,
I wonder anyone can help me find a faster algorithm to
get the values of unique ID (most ID has 2-3 values,
My data looks like:
ID Values
1 250
2 300
1 251
3 5000
4 600
10 521
3  5500
I would like output to look like:
ID, avg(values), stdev(values), value 1,val 2,val3,...

I used 2 for loops trying to get the values
for (i in 1:n){
  value <- NULL
  for(j in 1:m){
    if(data[j,1] == uniqueid[i]){
         value <- c(value, data[j,2])
Since both n and m are about 10000, the algorithm is
really slow.  I believe there is some function out
there that can do better than this in R. 



More information about the R-help mailing list