如何选择以R中某个子字符串开头的元组

如何选择以R中某个子字符串开头的元组,r,R,我有一个如下所示的数据框 > df[1:10,c("Uri","Latency")] Uri 1 /filters/test_group_1/test_datasource%20with%20space/test_application_

我有一个如下所示的数据框

> df[1:10,c("Uri","Latency")]
                                                                                                       Uri
1                          /filters/test_group_1/test_datasource%20with%20space/test_application_alias_100
2                                                          /applications?includeDashboards&includeMappings
3                                                                   /applications/test_application_alias_1
4                                                          /applications?includeDashboards&includeMappings
5                                                                 /applications/test_application_alias_200
6                                                                 /applications/test_application_alias_100
7    /filters/00000000-0000-0000-0000-000000000001/test_datasource%20with%20space/test_application_alias_0
8                                             /dashboards?dashboard=test_dashboard_alias_9&includeMappings
9               /filters/00000000-0000-0000-0000-000000000001/test_dataSource_1/test_application_alias_100
10 /filters/00000000-0000-0000-0000-000000000001/test_datasource%20with%20space/test_application_alias_100
   Latency
1      296
2     1388
3       58
4      833
5      239
6       60
7      217
8       36
9       86
10     112
我只想选择以/applications开头的行。请注意,Uri的其余部分可以是任何内容,并不重要

我可以通过下面的步骤得到精确的匹配

df[which(df$Uri == "/applications"),c("Uri","Latency")]
但是,我知道,因为我正在寻找一个子字符串,所以我可能需要进行一些通配符处理,在SQL中看起来是这样的

select * from <table_name> where Uri like '%/applications%'
select*从其中像“%/applications%”这样的Uri

如何在R中执行相同的操作我将使用正则表达式:

df[ grepl( "^\\/applications" , df[, "Uri"] ) , c("Uri","Latency") ]

我会使用正则表达式:

df[ grepl( "^\\/applications" , df[, "Uri"] ) , c("Uri","Latency") ]

假设
df$Uri
是一个字符向量,我将使用:

df[startsWith(df$Uri, "/applications"), ]

假设
df$Uri
是一个字符向量,我将使用:

df[startsWith(df$Uri, "/applications"), ]
可能只是
df[substr(df$Uri,1,nchar(“/applications”)=”/applications“,]”
?可能只是
df[substr(df$Uri,1,nchar(“/applications”)=”/applications“,]”