[R] how to transform string to Camel Case?

2013-04-15 Thread Liviu Andronic
Dear all,
Given the following vector:
 (z - c('R project', 'hello world', 'something Else'))
[1] R project  hello worldsomething Else

I know how to obtain all capitals or all lower case letters:
 tolower(z)
[1] r project  hello worldsomething else
 toupper(z)
[1] R PROJECT  HELLO WORLDSOMETHING ELSE

I saw the tocamel() function in 'rapport', but it doesn't do what I
want to achieve as it actually proceeds to camelCase/CamelCase the
strings:
 tocamel(z)
[1] RProject  helloWorldsomethingElse


But how should I proceed to obtain Camel Case? Here's what I'd like to get:
c('R Project', 'Hello World', 'Something Else')


Regards,
Liviu


-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

__
R-help@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread Pascal Oettli

Hi,

There is an example of how to do do what you are looking for in ?toupper

Regards,
Pascal

On 04/15/2013 03:50 PM, Liviu Andronic wrote:

Dear all,
Given the following vector:

(z - c('R project', 'hello world', 'something Else'))

[1] R project  hello worldsomething Else

I know how to obtain all capitals or all lower case letters:

tolower(z)

[1] r project  hello worldsomething else

toupper(z)

[1] R PROJECT  HELLO WORLDSOMETHING ELSE

I saw the tocamel() function in 'rapport', but it doesn't do what I
want to achieve as it actually proceeds to camelCase/CamelCase the
strings:

tocamel(z)

[1] RProject  helloWorldsomethingElse


But how should I proceed to obtain Camel Case? Here's what I'd like to get:
c('R Project', 'Hello World', 'Something Else')


Regards,
Liviu




__
R-help@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread Henrik Bengtsson
See for instance capitalize() in the R.utils package.

Henrik
On Apr 14, 2013 11:51 PM, Liviu Andronic landronim...@gmail.com wrote:

 Dear all,
 Given the following vector:
  (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:
  tolower(z)
 [1] r project  hello worldsomething else
  toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
  tocamel(z)
 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to get:
 c('R Project', 'Hello World', 'Something Else')


 Regards,
 Liviu


 --
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

 __
 R-help@r-project.org mailing list
 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread peter dalgaard

On Apr 15, 2013, at 08:50 , Liviu Andronic wrote:

 Dear all,
 Given the following vector:
 (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else
 
 I know how to obtain all capitals or all lower case letters:
 tolower(z)
 [1] r project  hello worldsomething else
 toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE
 
 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
 tocamel(z)
 [1] RProject  helloWorldsomethingElse
 
 
 But how should I proceed to obtain Camel Case? Here's what I'd like to get:
 c('R Project', 'Hello World', 'Something Else')

That'll be capitalization, not camel case, camel-casing is when wordsHaveHumps 
inTheMiddle. 

As for actually solving your problem, I'd try googling for regular expression 
to capitalize word and convert to use with gsub(). (I did do the googling, but 
regexps being  what they are - unreadable gibberish at first sight - I thought 
I'd leave the hard work for others...). Or, as Pascal points out: 
example(toupper).

-pd


 
 
 Regards,
 Liviu
 
 
 -- 
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
 
 __
 R-help@r-project.org mailing list
 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread Gergely Daróczi
Dear Liviu,

I have just updated tocamel to have a new argument, so the development
version of the package would produce:

  tocamel(z, upper = TRUE, sep = ' ')
[1] R Project  Hello WorldSomething Else

Best,
Gergely

PS #1: to install the dev branch you might give a try to the devtools
package:

 library(devtools)
 install_github('rapport', 'rapporter', 'development')

PS #2: Alex (cc) pls verify.


On 15 April 2013 08:50, Liviu Andronic landronim...@gmail.com wrote:

 Dear all,
 Given the following vector:
  (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:
  tolower(z)
 [1] r project  hello worldsomething else
  toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
  tocamel(z)
 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to get:
 c('R Project', 'Hello World', 'Something Else')


 Regards,
 Liviu


 --
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

 __
 R-help@r-project.org mailing list
 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.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread Liviu Andronic
On Mon, Apr 15, 2013 at 9:25 AM, Henrik Bengtsson h...@biostat.ucsf.edu wrote:
 See for instance capitalize() in the R.utils package.

Unfortunately this also fails when NA values are present:
 z - c(R project, hello world, something Else, NA)
 R.utils::capitalize(z)
[1] R project  Hello worldSomething Else NANA

Any pointers how to work around that? Thanks,
Liviu


 Henrik

 On Apr 14, 2013 11:51 PM, Liviu Andronic landronim...@gmail.com wrote:

 Dear all,
 Given the following vector:
  (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:
  tolower(z)
 [1] r project  hello worldsomething else
  toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
  tocamel(z)
 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to
 get:
 c('R Project', 'Hello World', 'Something Else')


 Regards,
 Liviu


 --
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

 __
 R-help@r-project.org mailing list
 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.



-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

__
R-help@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread Liviu Andronic
On Mon, Apr 15, 2013 at 9:20 AM, Pascal Oettli kri...@ymail.com wrote:
 There is an example of how to do do what you are looking for in ?toupper

Unfortunately this fails when NA values are present:
z - c(R project, hello world, something Else, NA)
 tocapwords(z)
[1] R Project  Hello WorldSomething Else NANA


Liviu


 Regards,
 Pascal


 On 04/15/2013 03:50 PM, Liviu Andronic wrote:

 Dear all,
 Given the following vector:

 (z - c('R project', 'hello world', 'something Else'))

 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:

 tolower(z)

 [1] r project  hello worldsomething else

 toupper(z)

 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:

 tocamel(z)

 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to
 get:
 c('R Project', 'Hello World', 'Something Else')


 Regards,
 Liviu






-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

__
R-help@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread Liviu Andronic
On Mon, Apr 15, 2013 at 10:10 AM, Gergely Daróczi gerg...@snowl.net wrote:
 Dear Liviu,

 I have just updated tocamel to have a new argument, so the development
 version of the package would produce:

  tocamel(z, upper = TRUE, sep = ' ')
 [1] R Project  Hello WorldSomething Else

Thanks for putting this in. Unfortunately as with other approaches it
fails on NA values:
z - c(R project, hello world, something Else, NA)
 tocamel(z, sep=' ', upper=T)
[1] R Project  Hello WorldSomething Else NANA

Can this be fixed? Thanks,
Liviu

__
R-help@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread Rainer M. Krug
Liviu Andronic landronim...@gmail.com writes:

 On Mon, Apr 15, 2013 at 9:25 AM, Henrik Bengtsson h...@biostat.ucsf.edu 
 wrote:
 See for instance capitalize() in the R.utils package.

 Unfortunately this also fails when NA values are present:
  z - c(R project, hello world, something Else, NA)
 R.utils::capitalize(z)
 [1] R project  Hello worldSomething Else NANA

 Any pointers how to work around that? Thanks,

would 

 R.utils::capitalize(z[is.character(z)])

work in your case?

Rainer


 Liviu


 Henrik

 On Apr 14, 2013 11:51 PM, Liviu Andronic landronim...@gmail.com wrote:

 Dear all,
 Given the following vector:
  (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:
  tolower(z)
 [1] r project  hello worldsomething else
  toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
  tocamel(z)
 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to
 get:
 c('R Project', 'Hello World', 'Something Else')


 Regards,
 Liviu


 --
 Do you know how to read?
 http://www.alienetworks.com/srtest.cfm
 http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
 Do you know how to write?
 http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

 __
 R-help@r-project.org mailing list
 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.
#secure method=pgpmime mode=sign

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, 
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :   +33 - (0)9 53 10 27 44
Cell:   +33 - (0)6 85 62 59 98
Fax :   +33 - (0)9 58 10 27 44

Fax (D):+49 - (0)3 21 21 25 22 44

email:  rai...@krugs.de

Skype:  RMkrug

__
R-help@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread Gergely Daróczi
On 15 April 2013 14:10, Liviu Andronic landronim...@gmail.com wrote:

 On Mon, Apr 15, 2013 at 10:10 AM, Gergely Daróczi gerg...@snowl.net
 wrote:
  Dear Liviu,
 
  I have just updated tocamel to have a new argument, so the development
  version of the package would produce:
 
   tocamel(z, upper = TRUE, sep = ' ')
  [1] R Project  Hello WorldSomething Else
 
 Thanks for putting this in. Unfortunately as with other approaches it
 fails on NA values:
 z - c(R project, hello world, something Else, NA)
  tocamel(z, sep=' ', upper=T)
 [1] R Project  Hello WorldSomething Else NANA

 Can this be fixed? Thanks,
 Liviu


I have added an extra check in the function for NA values before applying
`paste` at
https://github.com/Rapporter/rapport/compare/34ca6a35fb...a04abc8b21
Alex might not like it :)

Example:

  tocamel(z, upper = TRUE, sep = ' ')
[1] R Project  Hello WorldSomething Else NA

Best,
Gergely

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread Liviu Andronic
On Mon, Apr 15, 2013 at 2:22 PM, Gergely Daróczi gerg...@snowl.net wrote:
 I have added an extra check in the function for NA values before applying
 `paste` at
 https://github.com/Rapporter/rapport/compare/34ca6a35fb...a04abc8b21
 Alex might not like it :)

 Example:

  tocamel(z, upper = TRUE, sep = ' ')
 [1] R Project  Hello WorldSomething Else NA

Thanks! Now I'm getting somewhere:
z - c(R project, hello world, something Else, something-else,
NA)
 tocamel(z, sep=' ', upper=T, delim= )
[1] R Project  Hello WorldSomething Else Something-else
[5] NA


I hope Alex likes your fixes. Thanks,
Liviu

__
R-help@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread arun
HI,
You could use:
gsub((^|\\s+)([a-z]),\\1\\U\\2,z,perl=TRUE)
#[1] R Project  Hello World    Something Else

#or
 gsub(\\b([a-z]),\\U\\1,z,perl=TRUE)
#[1] R Project  Hello World    Something Else
A.K.



- Original Message -
From: Liviu Andronic landronim...@gmail.com
To: r-help r-h...@stat.math.ethz.ch
Cc: 
Sent: Monday, April 15, 2013 2:50 AM
Subject: [R] how to transform string to Camel Case?

Dear all,
Given the following vector:
 (z - c('R project', 'hello world', 'something Else'))
[1] R project      hello world    something Else

I know how to obtain all capitals or all lower case letters:
 tolower(z)
[1] r project      hello world    something else
 toupper(z)
[1] R PROJECT      HELLO WORLD    SOMETHING ELSE

I saw the tocamel() function in 'rapport', but it doesn't do what I
want to achieve as it actually proceeds to camelCase/CamelCase the
strings:
 tocamel(z)
[1] RProject      helloWorld    somethingElse


But how should I proceed to obtain Camel Case? Here's what I'd like to get:
c('R Project', 'Hello World', 'Something Else')


Regards,
Liviu


-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

__
R-help@r-project.org mailing list
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@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread Gabor Grothendieck
On Mon, Apr 15, 2013 at 2:50 AM, Liviu Andronic landronim...@gmail.com wrote:
 Dear all,
 Given the following vector:
 (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:
 tolower(z)
 [1] r project  hello worldsomething else
 toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
 tocamel(z)
 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to get:
 c('R Project', 'Hello World', 'Something Else')


Here is a one liner using gsubfn from the gsubfn package
(http://gsubfn.googlecode.com).  gsubfn is like gsubfn except the
second argument can be a function (or a list or a proto object).  The
regular expression here matches a space followed by any character.
For each such match gsubfn will call the function denoted by the
second argument using the two parenthesized portions of the regular
expression as the two arguments.  It supports an optional formula
notation to express the function for compactness so ... ~ toupper(..2)
denotes function(...) toupper(..2) which is equivalent to function(x,
y) toupper(y) .  It replaces the input with the output of that
function.  Finally we check if any of the components of the input are
NA and replace those with NA in the output:

 replace(gsubfn(( )(.), ... ~ toupper(..2), z), is.na(z), NA)
[1] RProject  helloWorldsomethingElse NA

__
R-help@r-project.org mailing list
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.


Re: [R] how to transform string to Camel Case?

2013-04-15 Thread Gabor Grothendieck
On Mon, Apr 15, 2013 at 10:56 AM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 On Mon, Apr 15, 2013 at 2:50 AM, Liviu Andronic landronim...@gmail.com 
 wrote:
 Dear all,
 Given the following vector:
 (z - c('R project', 'hello world', 'something Else'))
 [1] R project  hello worldsomething Else

 I know how to obtain all capitals or all lower case letters:
 tolower(z)
 [1] r project  hello worldsomething else
 toupper(z)
 [1] R PROJECT  HELLO WORLDSOMETHING ELSE

 I saw the tocamel() function in 'rapport', but it doesn't do what I
 want to achieve as it actually proceeds to camelCase/CamelCase the
 strings:
 tocamel(z)
 [1] RProject  helloWorldsomethingElse


 But how should I proceed to obtain Camel Case? Here's what I'd like to get:
 c('R Project', 'Hello World', 'Something Else')


 Here is a one liner using gsubfn from the gsubfn package
 (http://gsubfn.googlecode.com).  gsubfn is like gsubfn except the
 second argument can be a function (or a list or a proto object).  The
 regular expression here matches a space followed by any character.
 For each such match gsubfn will call the function denoted by the
 second argument using the two parenthesized portions of the regular
 expression as the two arguments.  It supports an optional formula
 notation to express the function for compactness so ... ~ toupper(..2)
 denotes function(...) toupper(..2) which is equivalent to function(x,
 y) toupper(y) .  It replaces the input with the output of that
 function.  Finally we check if any of the components of the input are
 NA and replace those with NA in the output:

 replace(gsubfn(( )(.), ... ~ toupper(..2), z), is.na(z), NA)
 [1] RProject  helloWorldsomethingElse NA

Above gsubfn is like gsubfn should read gsubfn is like gsub

Also here is a further simplification:

 replace(gsubfn( (.), toupper, z), is.na(z), NA)
[1] RProject  helloWorldsomethingElse NA


--
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

__
R-help@r-project.org mailing list
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.