根据行中的字符值提取特定列

发布于 2025-01-12 20:36:36 字数 690 浏览 2 评论 0原文

我有一个在第一行中包含字符的数据,如下所示,

       J   K    L   M  N  O  P
A      T   F    T   F  F  F  T   
B     14  15   10   2  3  4  78
C     10  47   15   9  6 12  12 
D     17  44   17   1  0 15  11
E      3  12   14   3  2 15  17

我只想提取 A 行中包含值“T”的列,

所以我想要的结果是这样的:

       J      L     P
A      T      T     T   
B     14     10    78
C     10     15    12 
D     17     17    11
E      3     14    17

另外,在第二次,我想知道如何使用两个条件执行相同的操作,例如:提取 A 列中包含值“T”和 D 行中包含值 17 的所有列,因此结果将是:

       J      L     
A      T      T      
B     14     10    
C     10     15    
D     17     17  
E      3     14    

谢谢

I have a data that contains character in the first row like this

       J   K    L   M  N  O  P
A      T   F    T   F  F  F  T   
B     14  15   10   2  3  4  78
C     10  47   15   9  6 12  12 
D     17  44   17   1  0 15  11
E      3  12   14   3  2 15  17

i want to extract only the columns that contain the value "T" in row A

so the result i want is this :

       J      L     P
A      T      T     T   
B     14     10    78
C     10     15    12 
D     17     17    11
E      3     14    17

also, in second time, i want to know how to do the same thing using two conditions, for example : extract all columns that contain value "T" in column A and value 17 in row D so the result will be :

       J      L     
A      T      T      
B     14     10    
C     10     15    
D     17     17  
E      3     14    

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清浅ˋ旧时光 2025-01-19 20:36:36

这是你的答案。

> df <- df[, df["A",] == "T" & df["D",] == 17]

您可以使用索引来过滤列。它支持逻辑语句,您可以将它们与 & 组合起来。

Here is your answer.

> df <- df[, df["A",] == "T" & df["D",] == 17]

You can use index to filter columns. It supports logical statements and you can combine them with &.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文