中执行相同的操作
我有一个数据框架,如下所示
> 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
我只想选择以/应用程序开头的那些行。请注意,其余的URI可能是任何东西,也不重要。
我可以通过以下内容获得确切的匹配项,
df[which(df$Uri == "/applications"),c("Uri","Latency")]
但是,由于我正在寻找一个子字符串,所以我知道,我可能必须进行一些通配符处理,在SQL中看起来像。
select * from <table_name> where Uri like '%/applications%'
我该如何在r
假设df$Uri
是角色向量,我会选择:
df[startsWith(df$Uri, "/applications"), ]
我会使用正则表达式:
df[ grepl( "^\/applications" , df[, "Uri"] ) , c("Uri","Latency") ]