loops - how to do looping in R -


hey guys want looping in r ; can me out

for eg have sum of points , want no of empid in 0-10 % of sum of points , on ;how in r

for eg have data as

empid               sumofpoints   1                       10   2                       30  

i want data

percentageofsumpoints       countofempid    0-10                        4   11-20                        5   21-30                        6 

and on.... how in r ,do have install package it

no need install package.see http://nunn.rc.fas.harvard.edu/groups/pica/wiki/1f131/

simple loop

 (i in 1:10){      print(i)  } 

in example, asssuming data stored in dataframe called df

res <- null groups <- c(0,10,20,30,40,...) (i in 2:length(groups)){     res <- rbind(res,c(paste(groups[i],groups[i-1],sep="-"),nrow(df[df$sumofpoints <= groups[i] & df$sumofpoints > groups[i-1],]))) } 

you can use apply functions if want avoid for statements. example have taken directly files

 x <- cbind(x1 = 3, x2 = c(4:1, 2:5))  dimnames(x)[[1]] <- letters[1:8]  apply(x, 2, mean, trim = .2) 

edit further how avoid loops


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -