cc.Rd
Split strings by comma into character vector(s)
cc(x, simplify)
x | Vector of comma separated character strings |
---|---|
simplify | Logical indicating whether to return a character vector (the default) when the length of x is one. This argument does nothing if the length of x is greater than 1. |
If length of x is 1 then a character vector otherwise a list of character vectors.
#> [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" #> [20] "t" "u" "v" "w" "x" "y" "z"## return as list cc(abcs, simplify = FALSE)#> [[1]] #> [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" #> [20] "t" "u" "v" "w" "x" "y" "z" #>## select columns mtcars[, cc("cyl,mpg,wt,gear")]#> cyl mpg wt gear #> Mazda RX4 6 21.0 2.620 4 #> Mazda RX4 Wag 6 21.0 2.875 4 #> Datsun 710 4 22.8 2.320 4 #> Hornet 4 Drive 6 21.4 3.215 3 #> Hornet Sportabout 8 18.7 3.440 3 #> Valiant 6 18.1 3.460 3 #> Duster 360 8 14.3 3.570 3 #> Merc 240D 4 24.4 3.190 4 #> Merc 230 4 22.8 3.150 4 #> Merc 280 6 19.2 3.440 4 #> Merc 280C 6 17.8 3.440 4 #> Merc 450SE 8 16.4 4.070 3 #> Merc 450SL 8 17.3 3.730 3 #> Merc 450SLC 8 15.2 3.780 3 #> Cadillac Fleetwood 8 10.4 5.250 3 #> Lincoln Continental 8 10.4 5.424 3 #> Chrysler Imperial 8 14.7 5.345 3 #> Fiat 128 4 32.4 2.200 4 #> Honda Civic 4 30.4 1.615 4 #> Toyota Corolla 4 33.9 1.835 4 #> Toyota Corona 4 21.5 2.465 3 #> Dodge Challenger 8 15.5 3.520 3 #> AMC Javelin 8 15.2 3.435 3 #> Camaro Z28 8 13.3 3.840 3 #> Pontiac Firebird 8 19.2 3.845 3 #> Fiat X1-9 4 27.3 1.935 4 #> Porsche 914-2 4 26.0 2.140 5 #> Lotus Europa 4 30.4 1.513 5 #> Ford Pantera L 8 15.8 3.170 5 #> Ferrari Dino 6 19.7 2.770 5 #> Maserati Bora 8 15.0 3.570 5 #> Volvo 142E 4 21.4 2.780 4## character vector with multiple strings x <- c("v1,v2,v3", "y1,y2,y5") ## convert strings into list of [split] character vectors cc(x)#> [[1]] #> [1] "v1" "v2" "v3" #> #> [[2]] #> [1] "y1" "y2" "y5" #>