R version 3.6.2 (2019-12-12) -- "Dark and Stormy Night"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R是自由软件,不带任何担保。
在某些条件下你可以将其自由散布。
用'license()'或'licence()'来看散布的详细条件。
R是个合作计划,有许多人为之做出了贡献.
用'contributors()'来看合作者的详细情况
用'citation()'会告诉你如何在出版物中正确地引用R或R程序包。
用'demo()'来看一些示范程序,用'help()'来阅读在线帮助文件,或
用'help.start()'通过HTML浏览器来看帮助文件。
用'q()'退出R.
[原来保存的工作空间已还原]
> foo<-c(13563,-14156,-14319,16981,12921,11979,9568,8833,-12968,8133)
> foo1<-foo^75
> foo1[which(!is.finite(foo1))]
[1] Inf -Inf -Inf Inf Inf -Inf
> !is.finite(foo1))
错误: 意外的')' in "!is.finite(foo1))"
> !is.finite(foo1)
[1] TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE FALSE
> foo1[!which(is.finite(foo1))]
numeric(0)
> foo1[which(is.finite(foo1))]
[1] 7.612764e+305 3.644077e+298 9.080657e+295 1.856983e+293
> foo1[which(is.infinite(foo1))]
[1] Inf -Inf -Inf Inf Inf -Inf
> foo1[which(is.finite(x=foo1))]
[1] 7.612764e+305 3.644077e+298 9.080657e+295 1.856983e+293
> foo1[which(is.infinite(x=foo1))]
[1] Inf -Inf -Inf Inf Inf -Inf
> is.infinite(x=foo1)
[1] TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE FALSE
> fool
错误: 找不到对象'fool'
> foo1
[1] Inf -Inf -Inf Inf Inf
[6] 7.612764e+305 3.644077e+298 9.080657e+295 -Inf 1.856983e+293
> which(is.finite(x=foo1))
[1] 6 7 8 10
> foo1[which(is.finite(x=foo1))]
[1] 7.612764e+305 3.644077e+298 9.080657e+295 1.856983e+293
> foo1[which(is.finite(x=foo1)|foo1>=0)]
[1] Inf Inf Inf 7.612764e+305 3.644077e+298
[6] 9.080657e+295 1.856983e+293
>
> bar<-matrix(data=c(77875.40,-35466.25,-39803.81,27551.45,-73333.85,55976.34,23764.30,36599.69,76694.82,-36478.88,-70585.69,47032.00),dim=c(3,4))
Error in matrix(data = c(77875.4, -35466.25, -39803.81, 27551.45, -73333.85, :
'dimnames' must be a list
> bar<-matrix(data=c(77875.40,-35466.25,-39803.81,27551.45,-73333.85,55976.34,23764.30,36599.69,76694.82,-36478.88,-70585.69,47032.00),nrow=3,ncol=4)
> bar
[,1] [,2] [,3] [,4]
[1,] 77875.40 27551.45 23764.30 -36478.88
[2,] -35466.25 -73333.85 36599.69 -70585.69
[3,] -39803.81 55976.34 76694.82 47032.00
> barchuli1<-bar^65/inf
错误: 找不到对象'inf'
> barchuli1<-bar^65/Inf
> barchuli1
[,1] [,2] [,3] [,4]
[1,] NaN 0 0 0
[2,] 0 NaN 0 NaN
[3,] 0 NaN NaN 0
> barchuli1[which(barchuli1!=0)]
numeric(0)
> which(barchuli1!=0)
integer(0)
> barchuli1[which(barchuli1>0)]
numeric(0)
> which(barchuli1>0)
integer(0)
> barchuli1[which(is.NaN(barchuli1))]
Error in is.NaN(barchuli1) : 没有"is.NaN"这个函数
> barchuli1[which(is.nan(barchuli1))]
[1] NaN NaN NaN NaN NaN
> bchl2<-bar^67+Inf
> bchl2
[,1] [,2] [,3] [,4]
[1,] Inf Inf Inf Inf
[2,] Inf NaN Inf NaN
[3,] Inf Inf Inf Inf
> bchl2[which((!is.nan(barchuli1)))]
[1] Inf Inf Inf Inf Inf Inf Inf
> bchl2[which(!is.nan(barchuli1))]
[1] Inf Inf Inf Inf Inf Inf Inf
> bchl3<-bar^67
> bchl3[which(bchl3>0|!is.finte(bchl3))]
Error in is.finte(bchl3) : 没有"is.finte"这个函数
> bchl3[which(bchl3>0|!is.finite(bchl3))]
[1] Inf 3.088011e+297 -Inf Inf 1.538072e+293
[6] 5.662214e+305 Inf -Inf Inf
> bchl3[which(bchl3>0|is.finite(bchl3))]
[1] Inf -6.880550e+304 -1.566575e+308 3.088011e+297
[5] Inf 1.538072e+293 5.662214e+305 Inf
[9] -4.537120e+305 Inf
> bchl3[which(is.finite(bchl3))]
[1] -6.880550e+304 -1.566575e+308 3.088011e+297 1.538072e+293
[5] 5.662214e+305 -4.537120e+305
> bar[bar^67==-Inf|is.finite(bar^67)]
[1] -35466.25 -39803.81 27551.45 -73333.85 23764.30 36599.69 -36478.88
[8] -70585.69
> bar[is.finite(bar^67)]
[1] -35466.25 -39803.81 27551.45 23764.30 36599.69 -36478.88
> bar[bar^67==-Inf]
[1] -73333.85 -70585.69
> bar^67==-Inf
[,1] [,2] [,3] [,4]
[1,] FALSE FALSE FALSE FALSE
[2,] FALSE TRUE FALSE TRUE
[3,] FALSE FALSE FALSE FALSE
> foo <- c(13563,-14156,-14319,16981,12921,11979,9568,8833,-12968,8133)
> ##(i)
> foo[is.finite(foo^75)]
[1] 11979 9568 8833 8133
> ##(ii)
> foo[-which(foo^75==-Inf)]
[1] 13563 16981 12921 11979 9568 8833 8133
> #(b)
> bar <- matrix(c(77875.4,-35466.25,-39803.81,27551.45,-73333.85,55976.34,23764.3,36599.69,76694.82,-36478.88,-70585.69,47032),nrow=3,ncol=4)
> ##(i)
> which(is.nan(bar^65/Inf),arr.ind=T)
row col
[1,] 1 1
[2,] 2 2
[3,] 3 2
[4,] 3 3
[5,] 2 4
> ##(ii)
> bar[!is.nan(bar^67+Inf)]
[1] 77875.40 -35466.25 -39803.81 27551.45 55976.34 23764.30 36599.69
[8] 76694.82 -36478.88 47032.00
> bar[bar^67!=-Inf]
[1] 77875.40 -35466.25 -39803.81 27551.45 55976.34 23764.30 36599.69
[8] 76694.82 -36478.88 47032.00
> ##(iii)
> bar[bar^67==-Inf|is.finite(bar^67)]
[1] -35466.25 -39803.81 27551.45 -73333.85 23764.30 36599.69 -36478.88
[8] -70585.69
> bar[is.finite(bar^67)]
[1] -35466.25 -39803.81 27551.45 23764.30 36599.69 -36478.88
> bar^67
[,1] [,2] [,3] [,4]
[1,] Inf 3.088011e+297 1.538072e+293 -4.53712e+305
[2,] -6.880550e+304 -Inf 5.662214e+305 -Inf
[3,] -1.566575e+308 Inf Inf Inf
> is.finite(bar^67)
[,1] [,2] [,3] [,4]
[1,] FALSE TRUE TRUE TRUE
[2,] TRUE FALSE TRUE FALSE
[3,] TRUE FALSE FALSE FALSE
> bar
[,1] [,2] [,3] [,4]
[1,] 77875.40 27551.45 23764.30 -36478.88
[2,] -35466.25 -73333.85 36599.69 -70585.69
[3,] -39803.81 55976.34 76694.82 47032.00
> foo<-c(4.3,2.2,NULL,2.4,NaN,3.3,3.1,NULL,3.4,NA)
> foo
[1] 4.3 2.2 2.4 NaN 3.3 3.1 3.4 NA
> length(foo)
[1] 8
> which(x=is.na(x=foo))
[1] 4 8
> is.null(x=foo)
[1] FALSE
> is.na(x=foo([8]))+4/NULL
错误: 意外的'[' in "is.na(x=foo(["
> is.na(x=foo[8])+4/NULL
numeric(0)
> list(c(7,7,NA,1,1.5,NA))
[[1]]
[1] 7.0 7.0 NA 1.0 1.5 NA
> names(alpha)<-list(c(7,7,NA,1,1.5,NA))
Error in names(alpha) <- list(c(7, 7, NA, 1, 1.5, NA)) :
找不到对象'alpha'
> alpha<-list(c(7,7,NA,1,1.5,NA))
> alpha
[[1]]
[1] 7.0 7.0 NA 1.0 1.5 NA
> alpha$beta
NULL
> alpha$beta<-c(which(is.na(x=alpha)))
> alpha
[[1]]
[1] 7.0 7.0 NA 1.0 1.5 NA
$beta
integer(0)
> alpha$beta<-which(is.na(x=alpha))
> alpha
[[1]]
[1] 7.0 7.0 NA 1.0 1.5 NA
$beta
named integer(0)
> bar<-list(c(7,7,NA,1,1.5,NA))
> names(bar)<-"alpha"
> bar
$alpha
[1] 7.0 7.0 NA 1.0 1.5 NA
> is.null(x=bar$beta)
[1] TRUE
> bar$beta <- which(x=is.na(x=bar$alpha))
> #(a)
> ##(i)
> foo <- array(data=1:36,dim=c(3,3,4))
> foo
, , 1
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
, , 2
[,1] [,2] [,3]
[1,] 10 13 16
[2,] 11 14 17
[3,] 12 15 18
, , 3
[,1] [,2] [,3]
[1,] 19 22 25
[2,] 20 23 26
[3,] 21 24 27
, , 4
[,1] [,2] [,3]
[1,] 28 31 34
[2,] 29 32 35
[3,] 30 33 36
> class(foo)
[1] "array"
> attributes(foo) #implicit
$dim
[1] 3 3 4
> ##(ii)
> bar <- as.vector(foo)
> bar
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
[25] 25 26 27 28 29 30 31 32 33 34 35 36
> class(bar)
[1] "integer"
> attributes(bar) #implicit
NULL
> ##(iii)
> baz <- as.character(bar)
> baz
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14"
[15] "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28"
[29] "29" "30" "31" "32" "33" "34" "35" "36"
> class(baz)
[1] "character"
> attributes(baz) #implicit
NULL
> ##(iv)
> qux <- as.factor(baz)
> qux
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
[25] 25 26 27 28 29 30 31 32 33 34 35 36
36 Levels: 1 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 25 26 27 ..、9
> class(qux)
[1] "factor"
> attributes(qux) #explicit
$levels
[1] "1" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "2" "20" "21"
[15] "22" "23" "24" "25" "26" "27" "28" "29" "3" "30" "31" "32" "33" "34"
[29] "35" "36" "4" "5" "6" "7" "8" "9"
$class
[1] "factor"
> ##(v)
> quux <- bar+c(-0.1,0.1)
> quux
[1] 0.9 2.1 2.9 4.1 4.9 6.1 6.9 8.1 8.9 10.1 10.9 12.1 12.9 14.1
[15] 14.9 16.1 16.9 18.1 18.9 20.1 20.9 22.1 22.9 24.1 24.9 26.1 26.9 28.1
[29] 28.9 30.1 30.9 32.1 32.9 34.1 34.9 36.1
> class(quux)
[1] "numeric"
> attributes(quux) #implicit
NULL
> foo.sum <- is.numeric(foo)+is.integer(foo)
> bar.sum <- is.numeric(bar)+is.integer(bar)
> baz.sum <- is.numeric(baz)+is.integer(baz)
> qux.sum <- is.numeric(qux)+is.integer(qux)
> quux.sum <- is.numeric(quux)+is.integer(quux)
> myfac <- factor(x=c(foo.sum,bar.sum,baz.sum,qux.sum,quux.sum),levels=c(0,1,2))
> myfac
[1] 2 2 0 0 1
Levels: 0 1 2
> as.numeric(myfac)
[1] 3 3 1 1 2
>