Reputation: 244
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!!
Upvotes: 0
Views: 116
Reputation: 824
We can use the t()
function to transpose your data, i.e
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")
Upvotes: 1