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 17.8 6 8 4 4 6 6 225 360 146.7 140.8 167.6 167.6
#> 3      16.4 17.3 15.2 10.4 10.4   8 8 8 8 8       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 26 8 8 8 8 4 4        318 304 350 400 79 120.3
#> 6        30.4 15.8 19.7 15 21.4   4 8 6 8 4            95.1 351 145 301 121
#>                      hp
#> 1    110 110 93 110 175
#> 2 105 245 62 95 123 123
#> 3   180 180 180 205 215
#> 4       230 66 52 65 97
#> 5 150 150 245 175 66 91
#> 6   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.43333 5.666667 201.2833 125.5000
#> 3 13.94000 8.000000 351.8800 192.0000
#> 4 26.58000 4.800000 157.1200 102.0000
#> 5 19.41667 6.666667 261.8833 146.1667
#> 6 20.46000 6.000000 202.6200 199.2000