当前位置:网站首页>13 r basic exercises
13 r basic exercises
2022-06-11 20:09:00 【THE ORDER】
> array(1:12,dim=c(2,3,2),dimnames=list(c("x1","x2"),c("x3","x4","x5"),c("x6","x7")))
, , x6
x3 x4 x5
x1 1 3 5
x2 2 4 6
, , x7
x3 x4 x5
x1 7 9 11
x2 8 10 12
> x=c("a","b","c","d","e","f")
> x[2]# Indexes 2, from 1 Start
[1] "b"
> x[c(1,3,5)] # Index vector
[1] "a" "c" "e"
> ind=(1:3)*2
> x[ind]
[1] "b" "d" "f"
> x[-3] # Don't 3 The location
[1] "a" "b" "d" "e" "f"
> x[-(1:3)] # Don't 1-3
[1] "d" "e" "f"
> "b">"a" #R You can compare the size of letters , In English order
[1] TRUE
> x>"a" # Vectorization , Return to one logic vector
[1] FALSE TRUE TRUE TRUE TRUE TRUE
> x[x>"a"]# Logical vector true , Returns the corresponding subset of positions
[1] "b" "c" "d" "e" "f"
> c(T,F,F)&c(T,T,F)# And true
[1] TRUE FALSE FALSE
> c(T,F,F)&&c(T,T,F)
[1] TRUE
> c(T,F,F)|c(T,T,F)# Or there may be a truth
[1] TRUE TRUE FALSE
> !c(T,F)# Not
[1] FALSE TRUE
> x[!x>"b"]#! Take the
[1] "a" "b"
> x=list(a=1:3,b=matrix(1,2,2),c=c(T,F))
> x# list
$a
[1] 1 2 3
$b
[,1] [,2]
[1,] 1 1
[2,] 1 1
$c
[1] TRUE FALSE
> x[1]
$a
[1] 1 2 3
> x[c(1,3)]
$a
[1] 1 2 3
$c
[1] TRUE FALSE
> x[c(T,F,T)]# Logical index
$a
[1] 1 2 3
$c
[1] TRUE FALSE
> x[c("a","b")]# Name Index
$a
[1] 1 2 3
$b
[,1] [,2]
[1,] 1 1
[2,] 1 1
> y=matrix(1:12,3,4)
> y
[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12
> y[c(1,3),c(T,F,T,F)]# Matrix indexing
[,1] [,2]
[1,] 1 7
[2,] 3 9
> y[c(1,2),-4]# No second place 4 Column
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
> y[1,]
[1] 1 4 7 10
> y[,2]
[1] 4 5 6
> y[1,,drop=F]#R Take elements from inside , The front and rear types are consistent , The matrix is a vector because drop=T Automatically simplifies
[,1] [,2] [,3] [,4]
[1,] 1 4 7 10
边栏推荐
- 2022-2028 current situation and future development trend of global and Chinese thermocouple belt Market
- moderlarts第二次作业
- Linux环境安装mysql数据库详细教程(含卸载和密码重置过程)
- STC hardware only automatic download circuit V2
- Golang learning notes - Basics
- Web3 product manager guide - Jason
- VS2010 cannot open when linking sql2008 database
- 7905 and TL431 negative voltage regulator circuit - regulator and floating circuit relative to the positive pole of the power supply
- Major work title and requirements of engineering earthquake resistance in autumn 21 [standard answer]
- Calculate the number of 926 in the string to the power of 9260 of 926
猜你喜欢

模拟Oracle锁等待与手工解锁

In 2021, the global ceramic substrate revenue will be about US $409.7 million, and it is expected to reach US $657.3 million in 2028

ICML 2022 | 基于结构化数据的异常检测再思考:我们究竟需要怎样的图神经网络?...

电源防反接和防倒灌 - 使用MOS 管和运放实现理想二极管

Detailed tutorial on installing MySQL database in Linux environment (including uninstallation and password reset process)

iMeta | 南科大夏雨组纳米孔测序揭示微生物可减轻高海拔冻土温室气体排放

In unity, opencv and QT are used to create a plugin (I)

moderlarts第一次培训

RTL arbiter design

Full list! 2022 Times Asia University Rankings announced!
随机推荐
浅聊对比学习(Contrastive Learning)第一弹
[Err] 1045 - Access denied for user ‘root‘@‘%‘ (using password: YES)
Leetcode 1992. 找到所有的农场组(可以,一次过)
Interface isolation principle
计算926的9260次方里的字符串里有多少个926
The latest test questions and answers for the eight major members (standard members) of Ningxia architecture in 2022
2022-2028 global and Chinese thermopile and microbolometer infrared detector Market Status and future development trend
Flutter Doctor affiche les solutions que xcode n'a pas installées
VS2010 cannot open when linking sql2008 database
Course design for construction organization, School of distance and continuing education, Dalian University of technology [standard answer]
Introduction to jobrunr, a distributed background job scheduler - jaxenter
Première formation sur les largeurs modernes
MySQL——事务
导师转我800块,让我仿真一个电路(电源设计)
2022Redis7.0x版本持久化详细讲解
WR | effect of micro nano plastic pollution in Jufeng formation of West Lake University on microbial flora and nitrogen removal function of Constructed Wetland
27. this指向问题
STC 纯硬件自动下载电路 V2
Calculate the number of 926 in the string to the power of 9260 of 926
[advanced MySQL] differences among 10 data types and how to optimize the table structure (3)