简体   繁体   中英

R paired samples analysis

I have a dataset with paired data from two timepoints (TP1 and TP2) for many customers (ID1, ID2, ID3...). I would like to create new columns (ID1-Diff, ID2-Diff, ...) for each customer and calculate the difference between TP2 and TP1. Here is how my R dataframe (df) columns looks like.

ID1-TP1   ID1-TP2   ID2-TP1   ID2-TP1   ID3-TP1   ID3-TP2 ...
2.1       3.3       1.4       1.9       2.1       5.4
0.9       2.4       5.6       1.2       2.3       1.1
...

Any idea how to approach this? Apply function maybe or a for loop? I am absolutely new to R, have tried many things with no success.

Appreciate your help.

I have a dataset with paired data from two timepoints (TP1 and TP2) for many customers (ID1, ID2, ID3...). I would like to create new columns (ID1-Diff, ID2-Diff, ...) for each customer and calculate the difference between TP2 and TP1. Here is how my R dataframe (df) columns looks like.

ID1-TP1   ID1-TP2   ID2-TP1   ID2-TP1   ID3-TP1   ID3-TP2 ...
2.1       3.3       1.4       1.9       2.1       5.4
0.9       2.4       5.6       1.2       2.3       1.1
...

Any idea how to approach this? Apply function maybe or a for loop? I am absolutely new to R, have tried many things with no success.

Appreciate your help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM