我正在尝试对列进行平均,但是,由于某些列缺少数据,因此NA的平均结束也是如此。 有没有办法找到多个列的平均值,同时从计算中排除任何NA数据?
到目前为止我使用的代码是:
### Calculate Bins ###
{pulse<-transmute(pulse, Question, Type, Student,Bin1=(Rt1+ Rt2 + Rt3+ Rt4)/4 , Bin2= (Rt5+Rt6+Rt7+Rt8)/4 , Bin3= (Rt9+Rt10+Rt11)/3)
}
但是,我不认为这是最好的方法。我的目标是使用Rt1-Rt4,Rt5-Rt8和Rt9-Rt11的三个列。就像这样:
Question Type Student Bin1 Bin2 Bin3
1 Q SNR 789331 4.25 4.00 4.666667
2 Q2 SNR 789331 3.75 2.50 3.000000
3 Q8 SNR 789331 4.00 2.50 3.333333
4 Q10 SNR 789331 4.00 2.75 3.333333
5 Q12 SNR 789331 3.50 3.25 3.666667
任何帮助将不胜感激!
我的数据如下:
> dput(pulse)
structure(list(Question = c("Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12", "Q",
"Q2", "Q8", "Q10", "Q12", "Q", "Q2", "Q8", "Q10", "Q12"), Type = c("SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR", "SNR",
"SNR", "SNR", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS",
"FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS",
"FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS",
"FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS",
"FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS",
"FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS",
"FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS",
"FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS",
"FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS", "FYS",
"FYS", "FYS", "FYS", "FYS", "FYS", "FYS"), Student = c("789331",
"789331", "789331", "789331", "789331", "805933", "805933", "805933",
"805933", "805933", "826523", "826523", "826523", "826523", "826523",
"832929", "832929", "832929", "832929", "832929", "838607", "838607",
"838607", "838607", "838607", "841903", "841903", "841903", "841903",
"841903", "843618", "843618", "843618", "843618", "843618", "852125",
"852125", "852125", "852125", "852125", "876406", "876406", "876406",
"876406", "876406", "879972", "879972", "879972", "879972", "879972",
"885650", "885650", "885650", "885650", "885650", "888712", "888712",
"888712", "888712", "888712", "903303", "903303", "903303", "903303",
"903303", "796882", "796882", "796882", "796882", "796882", "827911",
"827911", "827911", "827911", "827911", "830271", "830271", "830271",
"830271", "830271", "831487", "831487", "831487", "831487", "831487",
"834598", "834598", "834598", "834598", "834598", "836364", "836364",
"836364", "836364", "836364", "839802", "839802", "839802", "839802",
"839802", "855524", "855524", "855524", "855524", "855524", "873527",
"873527", "873527", "873527", "873527", "885409", "885409", "885409",
"885409", "885409", "894218", "894218", "894218", "894218", "894218",
"928026", "928026", "928026", "928026", "928026", "932196", "932196",
"932196", "932196", "932196", "955389", "955389", "955389", "955389",
"955389", "956952", "956952", "956952", "956952", "956952", "957206",
"957206", "957206", "957206", "957206", "957759", "957759", "957759",
"957759", "957759", "959200", "959200", "959200", "959200", "959200",
"962490", "962490", "962490", "962490", "962490", "968728", "968728",
"968728", "968728", "968728", "969005", "969005", "969005", "969005",
"969005", "971179", "971179", "971179", "971179", "971179", "976863",
"976863", "976863", "976863", "976863", "981621", "981621", "981621",
"981621", "981621", "952797", "952797", "952797", "952797", "952797",
"965873", "965873", "965873", "965873", "965873", "967416", "967416",
"967416", "967416", "967416", "975424", "975424", "975424", "975424",
"975424"), Rt1 = c(4, 3, 4, 4, 3, 5, 4, 5, 5, 5, 4, 4, 4, 5,
5, 4, 4, 4, 4, 3, 5, 5, 5, 5, 5, 2, 3, 4, 3, 4, 4, 5, 5, 4, 4,
3, 3, 3, 4, 3, 3, 3, 4, 4, 4, 3, 4, 5, 4, 3, 4, 4, 4, 3, 5, 4,
4, 4, 5, 5, 3, 4, 4, 4, 3, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 4, 5, 3, 4, 4, 4, 3, 3, 5, 4, 4, 2, 2, 3, 4, NA, NA,
NA, NA, NA, 3, 4, 4, 4, 3, NA, NA, NA, NA, NA, 5, 4, 5, 4, 4,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 4, 4, 3, 3, 4, 1, 3,
4, 5, 4, 4, 4, 5, 4, 4, NA, NA, NA, NA, NA), Rt2 = c(4, 4, 4,
4, 3, 4, 4, 4, 4, 4, 3, 4, 4, 5, 5, 4, 4, 4, 4, 3, 5, 5, 5, 5,
5, 4, 4, 4, 4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, 3, 3,
3, 3, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 3, 3, 3, 3, 3, 5, 5, 4, 4,
5, 5, 5, 4, 5, 5, 4, 3, 3, 4, 4, 5, 5, 5, 3, 3, 5, 4, 4, 4, 4,
3, 2, 2, 2, 2, 5, 5, 5, 5, 5, NA, NA, NA, NA, NA), Rt9 = c(4,
3, 3, 3, 3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 4, 3, 4, 4, 4, 4, 4, 4, 4, 5, 4, 3, 3, 4, 4, NA, NA,
NA, NA, NA, 3, 3, 3, 2, 4, 4, 4, 4, 4, 4, 5, 4, 4, 3, 3, 5, 4,
4, 4, 4, 3, 4, 4, 4, 4, 3, 1, 1, 1, 5, NA, NA, NA, NA, NA, 5,
5, 5, 5, 5, 5, 5, 5, 4, 5, NA, NA, NA, NA, NA, 3, 4, 3, 3, 4,
3, 3, 3, 2, 3, 5, 5, 5, 5, 5, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, 4, 5, 5, 4, 4, NA, NA, NA, NA, NA, 5, 4, 3, 4, 4, 4, 3, 3,
3, 2, NA, NA, NA, NA, NA, 1, 1, 1, 1, 1, 2, 3, 4, 4, 2, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 4, 1, 1, 1, 1, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA), Rt10 = c(5, 3, 3, 3, 4, NA, NA, NA, NA,
NA, 5, 4, 4, 4, 4, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 5, 4, 4, 3, 4, 4, 3, 3, 3, 4, 4, 3, 2, 3, 4,
4, 4, 4, 4, 4, 5, 5, 4, 3, 3, 5, 4, 4, 3, 4, 3, 4, 4, 4, 3, 3,
1, 1, 1, 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, NA, NA, NA)), .Names = c("Question", "Type",
"Student", "Rt1", "Rt2", "Rt3", "Rt4", "Rt5", "Rt6", "Rt7", "Rt8",
"Rt9", "Rt10", "Rt11"), row.names = c(NA, -205L), class = c("tbl_df",
"tbl", "data.frame"))
答案 0 :(得分:2)
生成行的平均值:
dataframe <- pulse[(number_of_rows_you_are_interested_in),]
rowMeans(dataframe, na.rm = TRUE)
答案 1 :(得分:0)
Rt1[!is.na(Rt1)]
上述代码通过排除Rt1
中的所有NA条目来返回缩减的数据帧您可以在列中使用此表达式
答案 2 :(得分:0)
我发现complete.cases()
对于只为您提供没有NAs的行特别有用
pulse <- pulse[complete.cases(pulse), ]
然后你应该能够计算出这个数据帧
此外,不必手动计算平均值,请按照此link的示例(这与您的问题非常相似)