# [R] help with splitting parts of data frame

Charles Berry ccberry at ucsd.edu
Sun Sep 28 18:33:57 CEST 2014

```Andras Farkas <motyocska <at> yahoo.com> writes:

>
> Dear All,
>
>
[snip details]
>
> ####
> first24 <-sum(unlist(c(subset(df, df[, 'simt'] > 0 & df[, 'simt'] <=
> z[1], 3))))
> second24 <-sum(unlist(c(subset(df, df[, 'simt'] > z[1] & df[, 'simt'] <=
> z[2], 3))))
> third24 <-sum(unlist(c(subset(df, df[, 'simt'] > z[2] & df[, 'simt'] <=
> z[3], 3))))
> fourth24 <-sum(unlist(c(subset(df, df[, 'simt'] > z[3] & df[, 'simt'] <=
> z[4], 3))))
> fifth24 <-sum(unlist(c(subset(df, df[, 'simt'] > z[4] & df[, 'simt'] <=
z[5], 3))))
> sixth24 <-sum(unlist(c(subset(df, df[, 'simt'] > z[5] & df[, 'simt'] <=
> z[6], 3))))
>
> last24 <-sum(unlist(c(subset(df, df[, 'simt'] > z[6] , 3))))
>
> my end result is to get this vector:
>
> c(first24,second24,third24,fourth24,fifth24,sixth24,last24)
>
> ####
>

Some hints:

see

?xtabs

for weighted tabulations and

?cut

for forming categories to tabulate.

Try to solve this using just those functions, 'c', and the '~' operator.

It can be done in one line.

HTH,

Chuck

```