本文介绍了比较多个数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些数据分析方面的帮助。

我确实有两个数据集(之前和之后),我想看看它们之间的差别有多大。

I need some help with data analysis.
I do have two datasets (before & after) and I want to see how big the difference is between them.

之前

11330    STAT1
2721    STAT2
52438    STAT3
6124    SUZY

之后

17401    STAT1
3462    STAT2
0    STAT3
72    SUZY

试图将它们与 tapply(在$ V1之前,$ V2之前,FUN =平均)分组。

但是我正在尝试绘制它,在x轴上不是得到组名而是数字。
我该如何绘制这样的轻拍数据(Y轴上的频率和X轴上的组名称)?

Tried to group them with tapply(before$V1, before$V2, FUN=mean).
But as I am trying to plot it, on x axis am not getting the group name but number instead.How can I plot such tapplied data (frequency on Y axis & group name on X axis)?

还想问一问正确的命令是什么R是否愿意比较这些数据集以找出它们之间的区别?

Also wanted to ask what is the proper command in R to compare such datasets as I am willing to find the difference between them?

已编辑

dput($ V2之前)

结构(1:4,.Label = c( STAT1, STAT2, STAT3, SUZY), class = factor)

dput(before$V2)
structure(1:4, .Label = c("STAT1", "STAT2", "STAT3","SUZY"),class = "factor")


推荐答案

这里有一些想法。

这是我认为您的数据的样子吗?

This is what I think your data look like?

before <- data.frame(val=c(11330,2721,52438,6124),
                     lab=c("STAT1","STAT2","STAT3","SUZY"))
after <- data.frame(val=c(17401,3462,0,72),
                     lab=c("STAT1","STAT2","STAT3","SUZY"))

将它们组合成一种罪恶带有期间变量的gle数据框:

Combine them into a single data frame with a period variable:

combined <- rbind(data.frame(before,period="before"),
      data.frame(after,period="after"))

重新格式化为矩阵并使用(base R) dotchart

Reformat to a matrix and plot with (base R) dotchart:

library(reshape2)
m <- acast(combined,lab~period,value.var="val")
dotchart(m)

具有 ggplot 的图:

library(ggplot2)
qplot(lab,val,colour=period,data=combined)

这篇关于比较多个数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 17:46