Skip to contents

Set new data to an existing c3d object.

Usage

c3d_setdata(x, newdata = NULL, newanalog = NULL)

Arguments

x

A c3d object to be modified.

newdata

The new point data that should be written to the c3d object. Usually a data frame of the class c3d_data as it is generated by c3d_data(). Defaults to NULL, which means that the point data will remain unchanged. The new point data can be in any format (wide, long, longest), but take care that the conventions of the format are met (see c3d_data() for details).

newanalog

The new analog data that should be written to the c3d object. Usually a data frame of the class c3d_analog as it is generated by c3d_analog(). Defaults to NULL, which means that the analog data will remain unchanged.

Value

The modified c3d object.

Details

This is a basic helper function to allow the modification of data within the c3dr package for later export. The function call updates the data (point and/or analog) and the appropriate parameters and header sections. Note that not all parameters can be updated based on insufficient information. For example, when using c3d_setdata() for updating the point data, the point label parameter gets updated (based on the column headers), but the point label descriptions will be unmodified. This can create minor inconsistencies in the resulting c3d object, which in the worst case can lead to corrupt data after export with c3d_write(). If you plan heavy modifications of the data before export make sure to manually check and update all relevant parameters as well as the residual data after calling c3d_setdata().

Examples

# Import example data
d <- c3d_read(c3d_example())

# remove last frame from point data and analog data (10 subframes for analog)
d_cut <- c3d_data(d)[-340, ]
a_cut <- c3d_analog(d)[-(3391:3400), ]

# write the new c3d object
d_new <- c3d_setdata(d, newdata = d_cut, newanalog = a_cut)
d_new
#> A c3d object with
#> - 55 data points and 339 frames
#> - 1.70 s measurement duration (200 fps)
#> - 69 analog channels (2000 fps)
#> - 2 force platforms with 3400 frames