Hi there!!!
I have a dataframe named transposed_physeq_rarefied
like this:
transposed_physeq_rarefied <- structure(list(OTU1 = c(10, 20, 30, 10, 40, 50), OTU2 = c(10, 20, 30, 10, 40, 50), OTU3 = c(10, 20, 30, 10, 40, 50) ), row.names = c("ERR260261_profile", "ERR260264_profile", "ERR260265_profile", "ERR260268_profile", "ERR260263_profile", "ERR275252_profile"), class = "data.frame")
I have another one dataframe called samplemat
:
samplemat <- structure(list(SampleID = c("ERR275252_profile", "ERR260268_profile",
"ERR260265_profile", "ERR260264_profile", "ERR260263_profile",
"ERR260261_profile", "ERR260260_profile", "ERR260259_profile",
"ERR260258_profile", "ERR260252_profile"), type = c("obese",
"control", "control", "control", "control", "obese", "control",
"control", "obese", "control")), row.names = c("ERR275252_profile",
"ERR260268_profile", "ERR260265_profile", "ERR260264_profile",
"ERR260263_profile", "ERR260261_profile", "ERR260260_profile",
"ERR260259_profile", "ERR260258_profile", "ERR260252_profile"
), class = "data.frame")
The two dataframes have some (or all) common rownames but not in the same order. Now, I want the rownames of the first dataframe (transposed_physeq_rarefied
) to be changed according to their respective value in the 2nd column (type
) of the second dataframe (samplemat
).
so, the rownames of transposed_physeq_rarefied
will be changed from
rownames(transposed_physeq_rarefied)
[1] "ERR260261_profile" "ERR260263_profile" "ERR260265_profile" "ERR260264_profile" "ERR260268_profile" "ERR275252_profile"
to
rownames(transposed_physeq_rarefied)
[1] "obese" "control" "control" "control" "control" "obese"
Please note that, the rownames in the two dataframes are not in the same order
Can anyone please help me?
Thanks and regards,
DC7