Hi everybody,

I have a large data table containing 2 sets (X,Y) of 4 paired and temporally connected observations (2017-2021) by actors, the first few lines of which are as below. I generally intend to calculate row-wise correlations between the 2 sets by the method of spearman.

data.frame(

stringsAsFactors = FALSE,

Actor = c("A", "B", "C", "D"),

X2017 = c(1066500, 100464, 77618, 349779),

X2018 = c(2093021, 189849, 43380, 322751),

X2019 = c(1792100, 238745, 30213, 462867),

X2020 = c(2404909, 291408, 29635, 525696),

X2021 = c(2421116, 402740, 23253, 622501),

Y2017 = c(26, 60, 12, 31),

Y2018 = c(28, 58, 12, 31),

Y2019 = c(29, 48, 12, 31),

Y2020 = c(29, 49, 12, 31),

Y2021 = c(29, 49, 12, 31)

)

I was able to find 2 corresponding and presumably suitable codes:

(1)

l <- apply(X = df, MARGIN = 1, FUN = function(x) cor.test(x[2:6], x[7:11]))

lapply(X = l, FUN = function(x) x$estimate)

(2)

cor = apply(df, MARGIN = 1, FUN = function(x) return(cor.test(x[2:6], x[7:11])$estimate))

Unfortunately, both return the error "x" must be numeric desite opposing assingnments.

Does anybody have an advice regarding this issue and/or the general coding?

Thank you so much in advance!