在数据框中查找值并返回值

问题描述 投票:0回答:1

我不确定为什么我很难找到应该是一个简单问题的答案。我有以下数据框:

> test
     Month        Equity - Rank FI - Rank Alts - Rank Reweight
[1,] "2006-01-31" "1"           "3"       "2"         "No"    
[2,] "2006-02-28" "1"           "3"       "2"         "No"    
[3,] "2006-03-31" "1"           "3"       "2"         "No"    
[4,] "2006-04-28" "1"           "3"       "2"         "No"    
[5,] "2006-05-31" "2"           "3"       "1"         "No"    
[6,] "2006-06-30" "1"           "3"       "2"         "No"    
[7,] "2006-07-31" "2"           "3"       "1"         "No"    
[8,] "2006-08-31" "1"           "3"       "2"         "No"  

我要做的就是按“月”搜索并返回该行的值。

我一直在尝试以下操作,但始终没有得到任何结果:

test[test$Month == '2006-03-31',]
# A tibble: 1 x 5
  Month               `Equity - Rank` `FI - Rank` `Alts - Rank` Reweight
  <dttm>                        <dbl>       <dbl>         <dbl> <chr>  

有人可以帮我弄清楚我在做什么错吗?谢谢。

r dataframe search matrix lookup
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.