[英]R, get entires from one column based on values of another column in R
我正在嘗試將列條目作為與數據框中的條目列表匹配的列表
顯示我正在嘗試做的事情:
Dataframe 命名為Tepo
| | 姓名 | 捷徑 |
| -------- | -------------- | ----------|
| 1 | 蘋果 | 一個 |
| 2 | 班南 | 乙|
| 3 | 橘子| 高分辨率照片| CLIPARTO ○ |
| 4 | 胡蘿卜 | C |
| 5 | 芒果 | 中號 |
| 6 | 草莓 | 小號 |
我有一個列表FruitList
作為 chr
>FruitList
>[1] "Bannas" "Carrots" "Mangos"
我想得到一個列表, shortcutList
,對應的列:
>shortcutList
>[1] "B" "C" "M"
我的嘗試:
shortcutList <- tepo$shorcut[tepo$name == FruiteList[]]
但是,我沒有得到想要的列表 output。
謝謝您的幫助
使用%in%
:
shortcutList <- tepo$shortcut[tepo$name %in% FruitList]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.