如果我有两个阵列
let array1 = [|1;2;3;4|]
let array2 = [|2;3|]
我如何使用过滤器将所有元素从一个中获取 例如,给我array2中的所有项目在array1 = 2和3
中这是我的尝试,但不正确
let result3 = array1 |> Array.filter(fun array1item -> array2 |> Array.filter(fun array1item2 -> array1item2 = array1item))
更新: 这是有效的,不确定它是否是最佳方式
let result3 = array1 |> Array.filter(fun array1item -> array2 |> Array.exists(fun array1item2 -> array1item2 = array1item))
答案 0 :(得分:3)
正如John Palmer建议的那样,使用install.packages("readr", repos=c("http://rstudio.org/_packages", "http://cran.rstudio.com"))
also installing the dependency ‘Rcpp’
Warning in install.packages :
cannot open: HTTP status was '404 Not Found'
Warning in install.packages :
cannot open: HTTP status was '404 Not Found'
Warning in install.packages :
unable to access index for repository http://rstudio.org/_packages/bin/windows/contrib/3.2
trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.2/Rcpp_0.12.1.zip'
Content type 'application/zip' length 3189720 bytes (3.0 MB)
downloaded 3.0 MB
trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.2/readr_0.1.1.zip'
Content type 'application/zip' length 1128358 bytes (1.1 MB)
downloaded 1.1 MB
package ‘Rcpp’ successfully unpacked and MD5 sums checked
Warning in install.packages :
cannot remove prior installation of package ‘Rcpp’
package ‘readr’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\m\AppData\Local\Temp\RtmpMd0LfX\downloaded_packages
可能更容易,也更有效率,但我不确定订购是否会得到保证。您可以使用Set.intersect
过滤数组,但最有可能效率较低:
Array.exists