-
每一行(记录),每一列(变量)查看全部
-
每一行(记录),每一列(变量)查看全部
-
构建列表的子集查看全部
-
数据框的子集查看全部
-
> x <-matrix(1:6, nrow=2, ncol=3) > x [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 > x[1,2] [1] 3 > x[2,3] [1] 6 > x[1,] [1] 1 3 5 > x[,3] [1] 5 6 > x[2,c(1,3)] [1] 2 6 > class(x[1,3]) [1] "integer" > x[1,2,drop = FALSE] [,1] [1,] 3 >查看全部
-
[1] 1 2 3 4 5 > x[x>5] [1] 6 7 8 9 10 > x>5 [1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE > x[x>5 & x<7] [1] 6 > x[x<3 | x>7] [1] 1 2 8 9 10 > y <- 1:4 > y [1] 1 2 3 4 > names(y) <- c("a","b","c","d") > y a b c d 1 2 3 4 > y[2] b 2 > y["b"] b 2 >查看全部
-
枚举简单的说也是一种数据类型,只不过是这种数据类型只包含自定义的特定数据,它是一组有共同特性的数据的集合。举个例子,颜色也可以定义成枚举类型,它可以包含你定义的任何颜色,当需要的时候,只需要通过枚举调用即可,另外比如说季节(春夏秋冬)、星期(星期一到星期日)等等这些具有共同投特征的数据都可以定义枚举。查看全部
-
构建子集 基本方法查看全部
-
小 结查看全部
-
> x <- Sys.time() > x [1] "2017-06-11 18:51:14 CST" > p <- POXITlt(x) Error: could not find function "POXITlt" > p <-as.POXITlt(x) Error: could not find function "as.POXITlt" > p <-as.POXITlt(x4) Error: could not find function "as.POXITlt" > p <-as.POSITlt(x4) Error: could not find function "as.POSITlt" > p <-as.POSIXlt(x4) > p <-as.POSIXlt(x) > p [1] "2017-06-11 18:51:14 CST" > class(x) [1] "POSIXct" "POSIXt" > p <-as.POSIXlt(x4) > p [1] "2018-06-11 UTC" > class(p) [1] "POSIXlt" "POSIXt" > names(unclass(p)) [1] "sec" "min" "hour" "mday" "mon" "year" "wday" "yday" "isdst" > p$sec [1] 0 > p$sec [1] 0 > p$min [1] 0 > as.POSIXct(x) [1] "2017-06-11 18:51:14 CST" > as.Date("2017-06-11") [1] "2017-06-11" > x5<- "jun 11,2017 22:38" > x5 [1] "jun 11,2017 22:38" > strptime(x5,”%M %D %Y %H %M") > strptime(x5,”%B %d,%Y %H:%M") > strptime function (x, format, tz = "") <bytecode: 0x075a66dc> <environment: namespace:base> > x1<- "jun 11,2017 22:38" > strptime(x5,”%B %d,%Y %H:%M") >查看全部
-
数据结构查看全部
-
> x <- data() > x > x <- date() > x [1] "Sun Jun 11 14:13:57 2017" > class(x) [1] "character" > x2 <- sys,date() Error: unexpected ',' in "x2 <- sys," > x2 <- sys.date() Error: could not find function "sys.date" > x2 <- Sys.date() Error: could not find function "Sys.date" > x2 <- Sys.Date() > x2 [1] "2017-06-11" > x3 <- Sys.Date() > x3 [1] "2017-06-11" > class(x2) [1] "Date" > class(x2,x3) Error in class(x2, x3) : 2 arguments passed to 'class' which requires 1 > class(x3) [1] "Date" > x3 <- as.Date("2017-06-11") > x3 [1] "2017-06-11" > class(x3) [1] "Date" > weekdays(x3) [1] "星期日" > months(x3) [1] "六月" > quarters(x3) [1] "Q2" > julian(x3) [1] 17328 attr(,"origin") [1] "1970-01-01" > x4 <- as.Date("2018-06-11") > x4 <- as.Date("2015-06-11") > X3-X4 Error: object 'X3' not found > x4-x3 Time difference of -731 days > x3 <- as.Date("2017-06-11") > x4 <- as.Date("2018-06-11") > x4-x3 Time difference of 365 days > as.numeric(x4-x3) [1] 365 >查看全部
-
> x <- data() > x > x <- date() > x [1] "Sun Jun 11 14:13:57 2017" >查看全部
-
> df <- data.frame(id=c(1,2,3,4),names=c("a","b","c","d"),gender=c(TRUE,TRUE,FALSE,FALSE)) > df id names gender 1 1 a TRUE 2 2 b TRUE 3 3 c FALSE 4 4 d FALSE > nrow(df) [1] 4 > ncol(df) [1] 3 > df2 <- data.frame(id=c(1,2,3,4),score=c(70,80,90,100)) > df2 id score 1 1 70 2 2 80 3 3 90 4 4 100 > data.matrix(df2) id score [1,] 1 70 [2,] 2 80 [3,] 3 90 [4,] 4 100 > save.image("F:\\R-3.0.3\\src\\library\\windlgs\\src\\数据框.RData") >查看全部
-
> x <- c(1,NA,2,NA,3) > X [1] 5 > x [1] 1 NA 2 NA 3 > is.na(x) [1] FALSE TRUE FALSE TRUE FALSE > is,nan(x) Error: unexpected ',' in "is," > is.nan(x) [1] FALSE FALSE FALSE FALSE FALSE > x <- c(1,NAN,2,NAN,3) Error: object 'NAN' not found > x <- c(1,NaN,2,NaN,3) > is.na(x) [1] FALSE TRUE FALSE TRUE FALSE > is.nan(x) [1] FALSE TRUE FALSE TRUE FALSE >查看全部
举报
0/150
提交
取消