[R] How to split two levels several times?
Rui Barradas
ruipbarradas at sapo.pt
Mon Jul 22 17:47:24 CEST 2013
Hello,
Try the following.
idx <- cumsum(c(TRUE, diff(dat$electrode == "electrode1") > 0))
split(dat, idx)
Hope this helps,
Rui Barradas
Em 22-07-2013 15:09, dennis1991 at gmx.net escreveu:
> Hi,
>
> I have a small problem with the function split() and would appreciate your help.
>
> I have a table called “XXX” with 2 columns and 49 rows. The 49 rows belong to 8 different levels (electrode1, ...,electrode8). I want to split the table always at the row where “electrode1” starts again so that I can export 7 individual dataframes (numbered “dataframe1” to ”dataframe7”) which contain always electrode1 as first level (always three rows) with the varying number of rows for electrodes2-8 below.
> I tried the split function with various setups:
>
> t <- as.factor(XXX$electrode)
>
> dataframeX <- split(XXX, f=(levels=t))
>
> But this doesn’t work. Could you please help. Thank you! Dennis
>
>
> This is the table "XXX"
>
> electrode length
>
> electrode1 5.7
> electrode1 6.3
> electrode1 6.2
> electrode2 11.4
> electrode2 9.7
> electrode1 5.7
> electrode1 6.3
> electrode1 6.2
> electrode3 14.2
> electrode3 14.8
> electrode3 12.6
> electrode1 5.7
> electrode1 6.3
> electrode1 6.2
> electrode4 17.0
> electrode4 16.3
> electrode4 17.8
> electrode4 18.3
> electrode4 16.9
> electrode4 18.5
> electrode1 ....
> .... ....
> electrode5 ....
> .... ....
> electrode1 ....
> electrode6 ....
> electrode1 ....
> electrode7 ....
> electrode1 ....
> electrode8 ....
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list