- R語言經典實例(原書第2版)
- (美)J.D.隆 保羅·蒂特
- 148字
- 2020-08-03 16:43:38
5.10 從列表中移除元素
5.10.1 問題
需要從列表中刪除某個元素。
5.10.2 解決方案
將NULL賦給要移除的元素。R將從列表中刪除它。
5.10.3 討論
要刪除列表元素,請按位置或按名稱選擇它,然后將NULL賦值給所選元素:
years <- list(Kennedy = 1960, Johnson = 1964, Carter = 1976, Clinton = 1994) years #> $Kennedy #> [1] 1960 #> #> $Johnson #> [1] 1964 #> #> $Carter #> [1] 1976 #> #> $Clinton #> [1] 1994 years[["Johnson"]] <- NULL # Remove the element labeled "Johnson" years #> $Kennedy #> [1] 1960 #> #> $Carter #> [1] 1976 #> #> $Clinton #> [1] 1994
也可以通過這種方式刪除多個元素:
years[c("Carter", "Clinton")] <- NULL # Remove two elements years #> $Kennedy #> [1] 1960
推薦閱讀
- Web前端開發技術:HTML、CSS、JavaScript(第3版)
- JavaScript修煉之道
- Pandas Cookbook
- Android開發精要
- PhpStorm Cookbook
- Ext JS 4 Web Application Development Cookbook
- WebRTC技術詳解:從0到1構建多人視頻會議系統
- UML 基礎與 Rose 建模案例(第3版)
- 單片機C語言程序設計實訓100例
- OpenResty完全開發指南:構建百萬級別并發的Web應用
- uni-app跨平臺開發與應用從入門到實踐
- 從程序員角度學習數據庫技術(藍橋杯軟件大賽培訓教材-Java方向)
- 分布式數據庫HBase案例教程
- Getting Started with Web Components
- Oracle SOA Suite 12c Administrator's Guide