Mean of hexadecimal numbers
Since these are color strings, you can use functions in the grDevices
package (other others) to manipulate them. E.g., you can convert them
to various color spaces and perhaps use the mean in one of those
spaces as your 'average color'.
> myColors <- c(One="#FF7C00",Two="#00BF40",Three="#FFFF00")
> col2rgb(myColors)
One Two Three
red 255 0 255
green 124 191 255
blue 0 64 0
> rgb2hsv(col2rgb(myColors))
One Two Three
h 0.08104575 0.3891798 0.1666667
s 1.00000000 1.0000000 1.0000000
v 1.00000000 0.7490196 1.0000000
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Sat, Apr 16, 2016 at 8:27 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote:
... and if you need to convert back: ?as.hexmode -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sat, Apr 16, 2016 at 8:20 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote:
?strtoi You'll have to remove the "#" first, e.g. via substring() -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sat, Apr 16, 2016 at 5:47 AM, Atte Tenkanen <attenka at utu.fi> wrote:
Hi, How would you calculate the "mean colour" of several colours, for
example
c("#FF7C00","#00BF40","#FFFF00")?
Yours,
Atte Tenkanen
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.