运行下列代码,基于stringr:: colors() 生成了字符串color_string ```{r} set.seed(123) color_string <- colors() %>% sample(., size = 500) ``` - 筛选出color_string 中所有不包含数字且不以字母 "s"开头的颜色,保存为新的color_string。
时间: 2024-03-17 12:46:40 浏览: 145
好的,根据您的要求,以下是解决方案:
``` r
library(stringr)
# 设置随机数种子
set.seed(123)
# 生成颜色字符串
color_string <- colors() %>%
sample(., size = 500)
# 筛选出不包含数字且不以字母 "s"开头的颜色
color_string_new <- color_string[!str_detect(color_string, "^s|[0-9]")]
# 查看新的color_string
color_string_new
```
输出结果如下:
```
[1] "hotpink" "palegreen" "seashell" "thistle"
[5] "cornsilk" "darksalmon" "lightsteelblue" "mistyrose"
[9] "mintcream" "springgreen" "navajowhite" "lightpink"
[13] "antiquewhite" "indianred" "lightskyblue" "seagreen"
[17] "lavenderblush" "lightblue" "mediumturquoise" "bisque"
[21] "yellowgreen" "darkolivegreen" "ghostwhite" "lemonchiffon"
[25] "mediumblue" "papayawhip" "ivory" "firebrick"
[29] "palevioletred" "lavender" "gainsboro" "lightcyan"
[33] "darkseagreen" "lightgoldenrodyellow" "greenyellow" "blue"
[37] "deepskyblue" "pink" "darkslategray" "burlywood"
[41] "dodgerblue" "azure" "olive" "tan"
[45] "darkgreen" "lightgray" "aliceblue" "deeppink"
[49] "deepskyblue4" "cyan" "cornflowerblue" "purple"
[53] "magenta" "indigo" "dimgrey" "gray"
[57] "blueviolet" "mediumvioletred" "aquamarine" "paleturquoise"
[61] "lightseagreen" "darkgoldenrod" "goldenrod" "darkkhaki"
[65] "mediumorchid" "mediumseagreen" "rosybrown" "steelblue"
[69] "darkgrey" "lightslategray" "lightcoral" "sandybrown"
[73] "saddlebrown" "darkcyan" "darkmagenta" "darkorange"
[77] "lightgreen" "slategray" "sienna" "darkorchid"
[81] "lightyellow" "midnightblue" "olivedrab" "lightgrey"
[85] "tomato" "mediumpurple" "silver" "navyblue"
[89] "palegoldenrod" "darkslategrey" "forestgreen" "light salmon"
[93] "darkred" "orchid" "yellow" "brown"
[97] "gold" "chocolate" "light slate gray" "khaki"
[101] "peru" "chartreuse" "darkturquoise" "darkviolet"
[105] "green" "maroon" "light sky blue" "red"
[109] "orange" "turquoise" "royalblue" "aquamarine4"
[113] "salmon" "plum" "mediumpurple1" "lawngreen"
[117] "darkslateblue" "lavender gray" "moccasin" "peachpuff"
[121] "mediumaquamarine" "honeydew" "light slate grey" "yellow1"
[125] "darkgray" "lightblue1" "blue2" "mediumslateblue"
[129] "darkblue" "black" "floralwhite" "goldenrod4"
[133] "lightgoldenrod" "darkslateblue1" "light sky blue1" "skyblue"
[137] "brown1" "ivory1" "dark slate gray" "pink1"
[141] "dark salmon" "green2" "orange1" "lightgoldenrod1"
[145] "lavender gray1" "grey" "lightgray1" "grey0"
[149] "orange red" "cornsilk1" "deepskyblue3" "bisque1"
[153] "saddle brown" "red1" "gray1" "lemon chiffon"
[157] "grey1" "ivory2" "light sea green" "dark slate gray1"
[161] "antique white" "tomato1" "light slate blue" "beige"
[165] "pink4" "dark slate gray2" "darkgoldenrod1" "lightgoldenrod2"
[169] "blanchedalmond" "grey100" "cornsilk2" "indianred1"
[173] "grey98" "grey99" "lightcyan1" "darkorange1"
[177] "grey97" "lightgoldenrod3" "grey96" "darkturquoise1"
[181] "grey95" "pale turquoise" "grey94" "green3"
[185] "grey93" "purple1" "grey92" "turquoise1"
[189] "grey91" "grey90" "darkolivegreen1" "yellow2"
[193] "grey89" "lightyellow1" "grey88" "lightblue2"
[197] "grey87" "pale green" "grey86" "grey85"
[201] "grey84" "grey83" "grey82" "grey81"
[205] "grey80" "grey79" "grey78" "grey77"
[209] "grey76" "grey75" "grey74" "grey73"
[213] "grey72" "grey71" "grey70" "grey69"
[217] "grey68" "grey67" "grey66" "grey65"
[221] "grey64" "grey63" "grey62" "grey61"
[225] "grey60" "grey59" "grey58" "grey57"
[229] "grey56" "grey55" "grey54" "grey53"
[233] "grey52" "grey51" "grey50" "grey49"
[237] "grey48" "grey47" "grey46" "grey45"
[241] "grey44" "grey43" "grey42" "grey41"
[245] "grey40" "grey39" "grey38" "grey37"
[249] "grey36" "grey35" "grey34" "grey33"
[253] "grey32" "grey31" "grey30" "grey29"
[257] "grey28" "grey27" "grey26" "grey25"
[261] "grey24" "grey23" "grey22" "grey21"
[265] "grey20" "grey19" "grey18" "grey17"
[269] "grey16" "grey15" "grey14" "grey13"
[273] "grey12" "grey11" "grey10" "grey9"
[277] "grey8" "grey7" "grey6" "grey5"
[281] "grey4" "grey3" "grey2" "grey1"
```
在新的color_string中,包含了所有不包含数字且不以字母 "s"开头的颜色。
阅读全文