[英]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. 我在转置数据帧时遇到问题,并在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). 我想获取时间序列(第1天或第4天)中“分类”中各项目的系数的相关性。 Which means I want to obtain the correlation of coefficient between each row and day1 to day4.
这意味着我想获得每一行与day1到day4之间的系数的相关性。
How could I do that? 我该怎么办?
Thanks for all the advices!! 感谢您的所有建议!
We can use the t()
function to transpose your data, ie 我们可以使用
t()
函数来转置您的数据,即
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. 然后,要计算相关系数,您可以使用
cor()
函数进一步探索。
dput(x)
: 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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.