我有一个my_cases <- list(
Species == "setosa" ~ "S",
TRUE ~ "other"
)
tiris <- tibble::as_tibble(iris)
tiris
#> # A tibble: 150 x 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <dbl> <dbl> <dbl> <dbl> <fct>
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 4.9 3 1.4 0.2 setosa
#> 3 4.7 3.2 1.3 0.2 setosa
#> 4 4.6 3.1 1.5 0.2 setosa
#> 5 5 3.6 1.4 0.2 setosa
#> 6 5.4 3.9 1.7 0.4 setosa
#> 7 4.6 3.4 1.4 0.3 setosa
#> 8 5 3.4 1.5 0.2 setosa
#> 9 4.4 2.9 1.4 0.2 setosa
#> 10 4.9 3.1 1.5 0.1 setosa
#> # … with 140 more rows
dplyr::mutate(tiris,
new_label = dplyr::case_when(!!!my_cases)
)
#> Error in eval_tidy(pair$lhs, env = default_env): object 'Species' not found
devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#> setting value
#> version R version 3.5.3 (2019-03-11)
#> os macOS Mojave 10.14.3
#> system x86_64, darwin15.6.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz America/New_York
#> date 2019-03-31
#>
#> ─ Packages ──────────────────────────────────────────────────────────────
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.5.3)
#> backports 1.1.3 2018-12-14 [1] CRAN (R 3.5.0)
#> callr 3.2.0 2019-03-15 [1] CRAN (R 3.5.1)
#> cli 1.1.0 2019-03-19 [1] CRAN (R 3.5.1)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.0)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 3.5.0)
#> devtools 2.0.1 2018-10-26 [1] CRAN (R 3.5.3)
#> digest 0.6.18 2018-10-10 [1] CRAN (R 3.5.0)
#> dplyr 0.8.0.1 2019-02-15 [1] CRAN (R 3.5.2)
#> evaluate 0.13 2019-02-12 [1] CRAN (R 3.5.2)
#> fansi 0.4.0 2018-10-05 [1] CRAN (R 3.5.0)
#> fs 1.2.7 2019-03-19 [1] CRAN (R 3.5.3)
#> glue 1.3.1 2019-03-12 [1] CRAN (R 3.5.1)
#> highr 0.8 2019-03-20 [1] CRAN (R 3.5.3)
#> htmltools 0.3.6 2017-04-28 [1] CRAN (R 3.5.0)
#> knitr 1.22 2019-03-08 [1] CRAN (R 3.5.2)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.0)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.5.0)
#> pillar 1.3.1 2018-12-15 [1] CRAN (R 3.5.0)
#> pkgbuild 1.0.3 2019-03-20 [1] CRAN (R 3.5.3)
#> pkgconfig 2.0.2 2018-08-16 [1] CRAN (R 3.5.0)
#> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.5.0)
#> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.5.0)
#> processx 3.3.0 2019-03-10 [1] CRAN (R 3.5.2)
#> ps 1.3.0 2018-12-21 [1] CRAN (R 3.5.0)
#> purrr 0.3.2 2019-03-15 [1] CRAN (R 3.5.1)
#> R6 2.4.0 2019-02-14 [1] CRAN (R 3.5.2)
#> Rcpp 1.0.1 2019-03-17 [1] CRAN (R 3.5.1)
#> remotes 2.0.2 2018-10-30 [1] CRAN (R 3.5.0)
#> rlang 0.3.3 2019-03-29 [1] CRAN (R 3.5.3)
#> rmarkdown 1.12 2019-03-14 [1] CRAN (R 3.5.1)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.5.0)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.5.0)
#> stringi 1.4.3 2019-03-12 [1] CRAN (R 3.5.1)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.5.2)
#> testthat 2.0.1 2018-10-13 [1] CRAN (R 3.5.0)
#> tibble 2.1.1 2019-03-16 [1] CRAN (R 3.5.1)
#> tidyselect 0.2.5 2018-10-11 [1] CRAN (R 3.5.0)
#> usethis 1.4.0 2018-08-14 [1] CRAN (R 3.5.0)
#> utf8 1.1.4 2018-05-24 [1] CRAN (R 3.5.0)
#> withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.0)
#> xfun 0.5 2019-02-20 [1] CRAN (R 3.5.2)
#> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.5.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/3.5/Resources/library
,我想更改其特定像素(例如100 x 100像素)的图像。我怎样才能做到这一点?
答案 0 :(得分:0)
您可以在该像素上添加一个矩形,并用一种颜色填充它:
var image: UIImage!
let color = UIColor.red
image = UIGraphicsImageRenderer(size: image.size).image { context in
image.draw(at: .zero)
let rectangle = CGRect(x: 100, y: 100, width: 1, height: 1)
color.setFill()
context.fill(rectangle)
}
或者您可能想将1 x 1像素的UIImage嵌入到其他UIImage中:
var onePixel: UIImage!
var image: UIImage!
image = UIGraphicsImageRenderer(size: image.size).image { context in
image.draw(at: .zero)
onePixel.draw(at: CGPoint(x: 100, y: 100))
}
或者您可能想将一个UIImage的像素移动到另一个UIImage:
var image1: UIImage!
var image2: UIImage!
// 1 x 1 size image, from position 100 x 100 of image2
var pixel: UIImage = UIGraphicsImageRenderer(bounds: CGRect(x: 100, y: 100, width: 1, height: 1)).image(actions: { _ in
image2.draw(at: .zero)
})
// The image1 with the pixel image embed in the position 100 x 100
var image1WithPixel = UIGraphicsImageRenderer(size: image1.size).image { (_) in
image1.draw(at: .zero)
pixel.draw(at: CGPoint(x: 100, y: 100))
}