- 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
推薦閱讀
- ArchiCAD 19:The Definitive Guide
- Project 2007項目管理實用詳解
- Canvas LMS Course Design
- 腦動力:C語言函數速查效率手冊
- 網上沖浪
- Hands-On Machine Learning on Google Cloud Platform
- 快學Flash動畫百例
- Visual Basic從初學到精通
- 計算機網絡技術基礎
- 四向穿梭式自動化密集倉儲系統的設計與控制
- 水晶石精粹:3ds max & ZBrush三維數字靜幀藝術
- 樂高機器人—槍械武器庫
- 網絡脆弱性掃描產品原理及應用
- 新一代人工智能與語音識別
- Hands-On Agile Software Development with JIRA