简体   繁体   中英

Calculate the correlation of coefficient if the variables are time series in r

I am having problem in transpose my dataframe, and make the correlation test in r.

my data is like:

Taxonomy Day1 Day2 Day3 Day4
A 1 2 3 4
B 5 6 7 8
C 9 10 11 12
D 13 14 15 16

I want to obtain the correlation of coefficient of each item in "Taxonomy" in the time series (Day1 o Day4). Which means I want to obtain the correlation of coefficient between each row and day1 to day4.

How could I do that?

Thanks for all the advices!!

We can use the t() function to transpose your data, ie

x_1 <- as.data.frame(t(x))

> x1
     A B  C  D
Day1 1 5  9 13
Day2 2 6 10 14
Day3 3 7 11 15
Day4 4 8 12 16

Then, to compute the coefficient of correlation, you can further explore using the cor() function.

dput(x) :

structure(list(Day1 = c(1, 5, 9, 13), Day2 = c(2, 6, 10, 14), 
    Day3 = c(3, 7, 11, 15), Day4 = c(4, 8, 12, 16)), .Names = c("Day1", 
    "Day2", "Day3", "Day4"), row.names = c("A", "B", "C", "D"), class = "data.frame")

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