how to split an array into separate arrays (R)? -


this question has answer here:

i have array:

>cent        b    e          r    f a19 60.46   0.77    -0.12   1 a15 16.50   0.53    0.08    2 a17 2.66    0.51    0.20    3 a11 36.66   0.40    -0.25   4 a12 38.96   0.91    0.23    1 a05 0.00    0.29    0.01    2 a09 3.40    0.35    0.03    3 a04 0.00    0.25    -0.03   4 

could 1 please me how split array 4 separate arrays last column «f» flag? in result see:

>cent1        b    e          r    f a19 60.46   0.77    -0.12   1 a12 38.96   0.91    0.23    1 >cent2        b    e          r    f a15 16.50   0.53    0.08    2 a05 0.00    0.29    0.01    2 …. 

should use for-loop , check flag "f" or exist build-in function? thanks.

we can use split create list of data.frames.

 lst <- split(cent, cent$f) 

note: here assumed 'cent' data.frame. if matrix

 lst <- split(as.data.frame(cent), cent[,"f"]) 

usually, enough of analysis. but, if need create multiple objects in global environment, can use list2env (not recommended)

 list2env(lst, paste0("cent", seq_along(lst)), envir= .globalenv) 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -