I am trying to add the Chronbachs Alpha calculation to every line.It should be a rolling calculation based on every 2 sales values.
so ,one calc for item 1 and item 2 ,then a separate one for item 2 and 3 ,for 3 and 4 ,etc.etc
so ,the Alpha calc should be instead of value ' z = 40/2.'
how do i put the Chronbachs Alpha code in that column Z ?
I have the following code:
input
df <- tibble::tribble(
~seq, ~date, ~sales,
1, "3/01/2017", 40,
2, "4/01/2017", 2,
3, "5/01/2017", 2,
4, "6/01/2017", 2,
5, "7/01/2017", 30,
6, "8/01/2017", 2,
7, "1/02/2017", 9,
8, "2/02/2017", 5,
9, "3/02/2017", 65,
10, "4/02/2017", 3,
11, "5/02/2017", 65
)
library(tibble)
add_column(df, z = 40/2, w = 1)
output
# A tibble: 11 x 5
seq date sales z w
1 1 3/01/2017 40 20 1
2 2 4/01/2017 2 20 1
3 3 5/01/2017 2 20 1
4 4 6/01/2017 2 20 1
5 5 7/01/2017 30 20 1
6 6 8/01/2017 2 20 1
7 7 1/02/2017 9 20 1
8 8 2/02/2017 5 20 1
9 9 3/02/2017 65 20 1
10 10 4/02/2017 3 20 1
11 11 5/02/2017 65 20 1
library(psy)
data(expsy)
cronbach(cbind(expsy[,c(1,3:10)],-1*expsy[,2]))