split.by.factor.fnc
Copy, Paste and Adapts
by.factor=split.by.factor.fnc(dat, which.factor='group')
Objetive
Create a list whose elements are all variables in a database at each level of a user-defined factor. This list can then be called to repeat a process or analysis per level of the selected factor.
Segmentation
Starting from widely used in this toobox data OBrienKaiser . We want to divide the database in as many items as levels of factor treatment .
by.treatment=split.by.factor.fnc(OBrienKaiser,
which.factor='treatment')
#------------------------------------------------------------------
# DIVIDE LA BASE DE DATOS POR FACTOR
#------------------------------------------------------------------
*** Se ha creado una lista con 3 elementos, correspondientes a los niveles
*** del factor treatment
*** Estos son los elementos de esa lista: control A B
*** Si deseas acceder a uno de ellos indicalo mediante: *** nombre.de.la.lista$que.lista
*** donde que.lista se refiere al elemento que deseas extraer.
We can access for example to the second element of that list by:
by.treatment$A or equivalent by.treatment[[2]]
treatment gender pre.1 pre.2 pre.3 pre.4 pre.5 post.1 post.2 post.3 post.4
6 A M 7 8 7 9 9 9 9 10 8
7 A M 5 5 6 4 5 7 7 8 10
8 A F 2 3 5 3 2 2 4 8 6
9 A F 3 3 4 6 4 4 5 6 4
post.5 fup.1 fup.2 fup.3 fup.4 fup.5
6 9 9 10 11 9 6
7 8 8 9 11 9 8
8 5 6 6 7 5 6
9 1 5 4 7 5 4