zoukankan      html  css  js  c++  java
  • R中的一些基础1106

    1.R中NA,NaN,Inf代表什么?

    NA:缺失数据

    NaN:无意义的数,比如sqrt(-2)

    Inf:正无穷大

    -Inf:负无穷大

    判断是否存在nan值

    is.na(x)#是否存在nan
    anyNA(x)
    
    sum(is.na(x))#存在几个nan值

    2.确定一个数值型vector的第一个最值(最大/最小)的下标:

    which.min(x)
    which.max(x)
    
    
    x    
    numeric (logical, integer or double) vector or an R object for which the internal coercion to double works whose min or max is searched for.

    3.对应的,确定一个矩阵每一行最值的下标:

    max.col(m, ties.method = c("random", "first", "last"))
    m    
    numerical matrix
    
    ties.method    
    a character string specifying how ties are handled, "random" by default;

    通常第一个参数默认是random,如果是first那么就返回相同最大值中第一列,last与此相反。

    4.判断一个逻辑向量中,值为TRUE的下标:

    which(x, arr.ind = FALSE, useNames = TRUE)
    arrayInd(ind, .dim, .dimnames = NULL, useNames = FALSE)
    which(LETTERS == "R")
    which(ll <- c(TRUE, FALSE, TRUE, NA, FALSE, FALSE, TRUE)) #> 1 3 7

    转自:https://stat.ethz.ch/R-manual/R-devel/library/base/html/which.html 

    5.返回输入值中的最大值和最小值

    转自:https://stat.ethz.ch/R-manual/R-devel/library/base/html/Extremes.html

    max(..., na.rm = FALSE)
    min(..., na.rm = FALSE)
    
    pmax(..., na.rm = FALSE)
    pmin(..., na.rm = FALSE)
    
    pmax.int(..., na.rm = FALSE)
    pmin.int(..., na.rm = FALSE)
    
    
    ...    
    numeric or character arguments (see Note).
    
    na.rm    
    a logical indicating whether missing values should be removed.
    用法:
    min(5:1, pi) #-> one number
    pmin(5:1, pi) #->  5  numbers
  • 相关阅读:
    2019ICPC上海站
    “浪潮杯”第九届山东省ACM大学生程序设计竞赛重现赛(2018)
    集合问题
    后缀数组
    141. 周期(KMP)
    求和(矩阵快速幂)
    大数(KMP)
    1270: [蓝桥杯2015决赛]完美正方形
    AC自动机
    8.26作业
  • 原文地址:https://www.cnblogs.com/BlueBlueSea/p/9913086.html
Copyright © 2011-2022 走看看