Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按R中的某个值获取行_R_Statistics_Aggregate - Fatal编程技术网

按R中的某个值获取行

按R中的某个值获取行,r,statistics,aggregate,R,Statistics,Aggregate,所以我有这个数据表,我想按专业对它进行分类(“Profissao”列)。 这样做的目的是按工作领域对每一列的答案进行平均 例如: 我需要选择一行中与“媒体”作业相关的每个“Aspeto-A”单元格,并对所有回答表单的媒体人员进行平均 数据表截图 数据的图片没有使用dput()有用。。由于我无法使用您的数据,我将使用R中包含的iris数据集: data(iris) str(iris) # 'data.frame': 150 obs. of 5 variables: # $ Sepal.Leng

所以我有这个数据表,我想按专业对它进行分类(“Profissao”列)。 这样做的目的是按工作领域对每一列的答案进行平均

例如: 我需要选择一行中与“媒体”作业相关的每个“Aspeto-A”单元格,并对所有回答表单的媒体人员进行平均

数据表截图


数据的图片没有使用
dput()有用。
。由于我无法使用您的数据,我将使用R中包含的
iris
数据集:

data(iris)
str(iris)
# 'data.frame': 150 obs. of  5 variables:
#  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#  $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
aggregate(.~Species, iris, mean)
#      Species Sepal.Length Sepal.Width Petal.Length Petal.Width
# 1     setosa        5.006       3.428        1.462       0.246
# 2 versicolor        5.936       2.770        4.260       1.326
# 3  virginica        6.588       2.974        5.552       2.026

毕竟没那么难。也许有更好的方法,但这个方法正在奏效。


AspetoA_selection请使用
dput
添加数据,并显示预期的数据输出。请阅读相关信息以及如何给出答案。@RonakShah找到了问题的解决方案,没有那么困难,只需要函数aggregate()。同样谢谢。非常感谢你,它帮了很多忙!我给自己留下了一个解释我所做的事情的答案。亲切的问候!