如何使用" max"从我的数据集中找到给定变量的最大值?功能?

时间:2015-03-07 19:19:40

标签: r function variables max

原谅我无知,但我试图找到" ID"的最大价值。在我的数据集中。

str (mvtweek1)
'data.frame':   191641 obs. of  11 variables:
 $ ID                 : int  8951354 8951141 8952745 8952223 8951608 8950793 8950760 8951611 8951802 8950706 ...
 $ Date               : Factor w/ 131680 levels "1/1/01 0:01",..: 42824 42823 42823 42823 42822 42821 42820 42819 42817 42816 ...
 $ LocationDescription: Factor w/ 78 levels "ABANDONED BUILDING",..: 72 72 62 72 72 72 72 72 72 72 ...
 $ Arrest             : logi  FALSE FALSE FALSE FALSE FALSE TRUE ...
 $ Domestic           : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
 $ Beat               : int  623 1213 1622 724 211 2521 423 231 1021 1215 ...
 $ District           : int  6 12 16 7 2 25 4 2 10 12 ...
 $ CommunityArea      : int  69 24 11 67 35 19 48 40 29 24 ...
 $ Year               : int  2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 ...
 $ Latitude           : num  41.8 41.9 42 41.8 41.8 ...
 $ Longitude          : num  -87.6 -87.7 -87.8 -87.7 -87.6 ...
  1. 使用max我如何首先找到变量的最大值" ID"
  2. 如何在Arrest变量
  3. 中找到有多少观测值为TRUE
  4. 如何找到有多少观察值的ALLEY的LocationDescription值?
  5. 我需要在R中使用什么功能来提取日期和时间。
  6. 在哪里可以找到这些命令及其功能的简单列表。例如,我在手册中找到了max(),但是当我试图找到" ID"的变量时,它没有工作。
  7. 我刚刚开始并且很难确定如何正确加载数据集。我不知道我需要添加命令header = T.有没有这方面的教程?

    THX

2 个答案:

答案 0 :(得分:0)

也许我在问题中遗漏了一些细微差别,但这就是我如何处理这些问题。

找到最大值:

maxID <- max(mvtweek1$ID)

Arrest为多少行为TRUE:

arrestCount <- nrow(mvtweek1[mvtweek1$Arrest==TRUE,])

小巷有多少个地方:

numAlley <- nrow(mvtweek1[mvtweek1$LocationDescription=="ALLEY",])

要转换为日期,请参阅strptime上的此链接。

答案 1 :(得分:0)

聚合(mvtweek1 $ ID,函数(x)max(x))

相关问题