- Machine Learning with R Quick Start Guide
- Iván Pastor Sanz
- 122字
- 2021-06-24 16:01:29
Vector indexing
Elements of a vector can be arranged in several haphazard ways, which can make it difficult to access them when needed. Hence, indexing makes it easier to access the elements.
You can have any type of index vectors, from logical, integer, and character.
Vector of integers starting from 1 can be used to specify elements in a vector, and it is also possible to use negative values.
Let's see some examples of indexing:
- Returns the nth element of x:
x <- c(9,8,1,5)
- Returns all x values except the nth element:
x[-3]
## [1] 9 8 5
- Returns values between a and b:
x[1:2]
## [1] 9 8
- Returns items that are greater than a and less than b:
x[x>0 & x<4]
## [1] 1
Moreover, you can even use a logical vector. In this case, either TRUE or FALSE will be returned if an element is present at that position:
x[c(TRUE, FALSE, FALSE, TRUE)]
## [1] 9 5
推薦閱讀
- PPT,要你好看
- GNU-Linux Rapid Embedded Programming
- Hands-On Internet of Things with MQTT
- 大數據專業英語
- Cloud Analytics with Microsoft Azure
- AWS Administration Cookbook
- Salesforce for Beginners
- 新編計算機圖形學
- TensorFlow Reinforcement Learning Quick Start Guide
- Visual C++項目開發案例精粹
- 生物3D打印:從醫療輔具制造到細胞打印
- 簡明學中文版Flash動畫制作
- 案例解說Delphi典型控制應用
- C#編程兵書
- Learning OpenShift