avoid for loop in R -


I am the root level in R. It is better to rewrite the loops by applying it. But for the following problem, I do not know how to get it. Can anyone help? Or some similar examples recommend?

  data (iris) ## Iris is a dataframe N & lt; - For NOCL (Iris) (i in 1: (N-1)) {subset and lt; - Iris [, C (i, n)] ## Remove ith column and last column for the analysis result & lt; - Some functions (subsets) ## Subset score [i] & lt; Analysis - Results $ score splitVal [i] & lt; - Results $ splitVal}    

You can do this easily:

  data (iris) some functions & lt; - Function (x) {list (score = mean (x [, 1]), split val = mean (x [, 1])}} n <- ncol (iris) sapply (1: (n -1) , Function (i, dataset, n) {subset & lt; - dataset [, c, (i, n)] ## Remove ith column and last column for analysis result & lt; - Some functions (subsets) ## Subset Score (score = result $ score, split wheel = result $ split val)}, dataset = iris, n = n   

will remove this result: [, 1] [, 2] [, 3] [, 4] score 5.843333, 3.057333, 3.758, 1.199333, and Split Val 5.800000 3.000000 4.350 1.300000

It may be appropriate to do the same with the implementation of H as it is useless using By making it easy to switch to parallel programming.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -