This function converts counts or rates to proportions.

props(traj, id_field = TRUE, scale = 1, digits = 4)

Arguments

traj

[matrix (numeric)]: longitudinal data. Each row represents an individual trajectory (of observations). The columns show the observations at consecutive time points.

id_field

[numeric or character] Whether the first column of the traj is a unique (id) field. Default: FALSE. If TRUE the function recognizes the second column as the first time step.

scale

[numeric] To scale the 'proportion' measures. Default: 1

digits

[numeric] Specifying number of digits to approximate the output to. Default: 4.

Value

A dataframe of proportion measures

Details

Given a matrix of observations (counts or rates), this function converts each observation to a proportion equivalent to the sum of each column. In other words, each observation is divided by the sum of the column where it is located, i.e. prop = [a cell value] / sum[corresponding column]

Examples

trajectry <- data_imputation(traj, id_field = TRUE, method = 2, replace_with = 1, fill_zeros = FALSE) #filling the missing values
#> [1] "8 entries were found/filled!"
trajectry <- props(trajectry$CompleteData, id_field = TRUE, scale=1, digits=4) print(trajectry)
#> location_ids X2001 X2002 X2003 X2004 X2005 X2006 X2007 X2008 X2009 #> 1 E01012628 0.0385 0.0000 0.0146 0.0308 0.0159 0.0000 0.0155 0.0519 0.0000 #> 2 E01004768 0.1154 0.1254 0.0291 0.0615 0.1111 0.0895 0.0155 0.0390 0.0222 #> 3 E01004803 0.0513 0.0584 0.0000 0.1538 0.0317 0.0537 0.0932 0.0779 0.1778 #> 4 E01004804 0.0897 0.0584 0.1310 0.0462 0.0317 0.0698 0.0932 0.0390 0.0444 #> 5 E01004807 0.0256 0.0763 0.0728 0.0769 0.0952 0.0780 0.0466 0.0649 0.0889 #> 6 E01004808 0.1026 0.0974 0.1164 0.0615 0.0159 0.0895 0.0932 0.0130 0.0222 #> 7 E01004788 0.0256 0.0779 0.0396 0.0308 0.0317 0.0716 0.0155 0.0390 0.0000 #> 8 E01004790 0.1282 0.1752 0.2474 0.2000 0.2381 0.2439 0.2171 0.2468 0.2000 #> 9 E01004805 0.1026 0.0974 0.1455 0.1077 0.1429 0.0716 0.0840 0.0779 0.0667 #> 10 E01004806 0.3205 0.2336 0.2037 0.2308 0.2857 0.2326 0.3261 0.3506 0.3778