using loops or lapply in R -


i'm trying iteratively loop through subsets of r df having trouble. df$a contains values 0-1000. i'd subset df based on each unique value of df$a, manipulate data, save newdf, , concatenate (rbind) 1000 generated newdf's 1 single df.

my current code single iteration (no loops) this:

dfa = 1 dfa_1 <- subset(df, == dfa) :: ddply commands on dfa_1 altering length , content :: 

edit: clarify, in single iteration version, once have subset, have been using ddply count number of rows contain values. not subsets have values, result can of variable length. thus, have been appending result skeleton df accounts cases in subset of df might not have rows containing values expect (i.e., nrow = 0). ideally, wind subset being fixed length each instance of a. how can incorporate single (or multiple) plyr or dplyr set of code?

my issue loops length not variable, rather unique values of df$a.

my questions follows: 1. how use loop (or form of apply) perform operation? 2. can these operations used manipulate data in addition generate iterative df namess (e.g., df named dfa_1 dfa_x x 1 of values of df$a 1 1000). current thinking i'd rbind 1000 dfa_x's, though seems cumbersome.

many assistance.

you should use dplyr package this. want take form:

library(dplyr) df %>%   group_by(a) %>%   summarize( . . . )  

it easier do, easier read, less prone error, , faster.

http://cran.rstudio.com/web/packages/dplyr/vignettes/introduction.html


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -