如何将摘要的输出存储在变量中?

时间:2015-08-30 13:56:36

标签: r

考虑以下代码:

baseball <- read.csv("c:\\Users\\Jim\\Downloads\\MLB2008.csv", header = T)
summary(baseball$SALARY)

产生以下输出:

    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
  400000   600000  2200000  4349000  6250000 28000000

我的问题:

  • 如何将'Median'(即2200000)的内容存储在我以后可以使用的变量中?

例如,而不是:

baseball$Salary_GTE_THAN_MEDIAN <- as.numeric(2200000<=baseball$SALARY)

我想写:

baseball$Salary_GTE_THAN_MEDIAN <- as.numeric(median_salary<=baseball$SALARY)

2 个答案:

答案 0 :(得分:1)

使用median命令。使用

median(x, na.rm = FALSE)

https://stat.ethz.ch/R-manual/R-devel/library/stats/html/median.html

答案 1 :(得分:1)

我们可以通过输出的List<String> supportedFocusMode = parameters.getSupportedFocusModes(); boolean isSupportFocusMode = parameters.getSupportedFocusModes().contains(focusMode); if (supportedFocusMode != null && isSupportFocusMode) { parameters.setFocusMode(focusMode); int maxNumFocusAreas = parameters.getMaxNumFocusAreas(); if (maxNumFocusAreas > 0) { int areaHalfSize = 400; Rect middelArea = new Rect(-areaHalfSize, -areaHalfSize, areaHalfSize, areaHalfSize); //between -1000 to 1000 List<Camera.Area> focusAreas = new ArrayList<Camera.Area>(); focusAreas.add(new Camera.Area(middelArea, 1)); parameters.setFocusAreas(focusAreas); } } summary输出进行子集化。

names

使用可重现的例子

median_salary <- summary(baseball$SALARY)['Median']
baseball$Salary_GTE_THAN_MEDIAN <- as.numeric(median_salary<=baseball$SALARY)