繁体   English   中英

R,根据 R 中另一列的值从一列中获取整数

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM