Compress a vector or data frame

syncing_df_compress(
  x,
  newLength,
  sep = " ",
  compressFun = NULL,
  compressFunPart = NULL,
  silent = rock::opts$get("silent")
)

syncing_vector_compress(
  x,
  newLength,
  sep = " ",
  compressFun = NULL,
  compressFunPart = NULL,
  silent = rock::opts$get("silent")
)

Arguments

x

The vector or data frame

newLength

The new length (or number of rows for a data frame)

sep

When not specifying compressFun and compressFunPart, the paste function is used to combine elements, and in that case, sep is passed to paste as separator.

compressFun

If specified, when compressing streams, instead of pasting elements together using separator sep, the vectors are passed to function compressFun, which must accept a vector (to compress) and a single integer (with the desired resulting length of the vector).

compressFunPart

A function to apply to the segments that are automatically created; this can be passed instead of compressFun.

silent

Whether to be silent or chatty.

Value

The compressed vector or data frame

Examples

rock::syncing_vector_compress(
  1:10,
  3
);
#> [1] "1 2 3"    "4 5 6"    "7 8 9 10"

rock::syncing_df_compress(
  mtcars[, 1:4],
  6
);
#>                             mpg         cyl                            disp
#> 1          21 21 22.8 21.4 18.7   6 6 4 6 8             160 160 108 258 360
#> 2      18.1 14.3 24.4 22.8 19.2   6 8 4 4 6       225 360 146.7 140.8 167.6
#> 3 17.8 16.4 17.3 15.2 10.4 10.4 6 8 8 8 8 8 167.6 275.8 275.8 275.8 472 460
#> 4      14.7 32.4 30.4 33.9 21.5   8 4 4 4 4        440 78.7 75.7 71.1 120.1
#> 5      15.5 15.2 13.3 19.2 27.3   8 8 8 8 4              318 304 350 400 79
#> 6     26 30.4 15.8 19.7 15 21.4 4 4 8 6 8 4      120.3 95.1 351 145 301 121
#>                        hp
#> 1      110 110 93 110 175
#> 2       105 245 62 95 123
#> 3 123 180 180 180 205 215
#> 4         230 66 52 65 97
#> 5      150 150 245 175 66
#> 6  91 113 264 175 335 109

rock::syncing_df_compress(
  mtcars[, 1:4],
  6,
  compressFunPart = mean
);
#>        mpg      cyl     disp       hp
#> 1 20.98000 6.000000 209.2000 119.6000
#> 2 19.76000 5.600000 208.0200 126.0000
#> 3 14.58333 7.666667 321.1667 180.5000
#> 4 26.58000 4.800000 157.1200 102.0000
#> 5 18.10000 7.200000 290.2000 157.2000
#> 6 21.38333 5.666667 188.9000 181.1667