Re: [R] growing a list sequentially -- memory management

2008-11-14 Thread erwann rogard
Thank you all for your answers. I think I have enough to keep going:

As pointed out it is probably not growing a list of objects each of size
6824 bytes that is the source of the problem per se (even if the list is not
pre-allocated), but rather a memory leak with the function fun within the
loop. I'm not providing the full example here because the code spans several
files.

Nonetheless the body of fun itself contains deeply nested lists, some which
are temporary and others which are part of the return value. So i'm now
trying to see what to do about these nested lists instead. About memory
leak: my assumption was that the memory needed for a temporary object (i.e.
defined within the body of a function) would be redeemed after the function
call, but perhaps i'm wrong about that (no automatic garbage collection)?


On Fri, Nov 14, 2008 at 6:37 AM, Patrick Burns [EMAIL PROTECTED]wrote:

 The recommended technique is to create objects
 as their final size and then subscript into them
 with your data.

 My intuition (which is often brutally wrong) tells
 me that your case should not be overly traumatic.
 So I'm suspicious that you are fragmenting memory
 in other ways as well.

 Patrick Burns
 [EMAIL PROTECTED]
 +44 (0)20 8525 0696
 http://www.burns-stat.com
 (home of S Poetry and A Guide for the Unwilling S User)


 erwann rogard wrote:

 hello,

 i have something like:

 out-list()

 for(i in 1:n){
  data-gen(...) #fixed size data
  out[[i]]- fun(data)
 }



 object.size(out[[1]])


 6824

 In principle 1 GB should allow

 n = 1024^3/6824 = 157347?

 i have about 2GB are not taken by other processes. however, I can see the
 memory shrinking quite rapidly on my system monitor and have to stop the
 simulation after only n=300. why such a discrepancy? any remedy?

 x86_64-pc-linux/RKWard/R2.8.0/ 4GB

 thanks.

[[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.






[[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.


[R] growing a list sequentially -- memory management

2008-11-13 Thread erwann rogard
hello,

i have something like:

out-list()

for(i in 1:n){
 data-gen(...) #fixed size data
 out[[i]]- fun(data)
}

 object.size(out[[1]])
6824

In principle 1 GB should allow

n = 1024^3/6824 = 157347?

i have about 2GB are not taken by other processes. however, I can see the
memory shrinking quite rapidly on my system monitor and have to stop the
simulation after only n=300. why such a discrepancy? any remedy?

x86_64-pc-linux/RKWard/R2.8.0/ 4GB

thanks.

[[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.


[R] trellis: conditional statements within a panel function

2008-10-31 Thread erwann rogard
hello,

what i'm trying to achieve is shown in the comment (# ...) below, which is
surely very wrong, but probably intuitively more meaningful that i can
provide in words.

xyplot(y~x2|x1+which,data=make.groups(
  a=data.a,
  b=data.b,
  c=data.c
 ),
 panel=function(...){
  panel.abline(a=0,b=0)
  panel.points(...)
  # if(x1==0  which==a) panel.abline(...)
 },
 layout=c(2,3),
 pch=20,
 ylim=c(-10,10),
 xlab=x2,
 cex=0.5
)

thank!

[[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] Arrays of Trellis plots

2008-10-29 Thread erwann rogard
hi,

xyplot(y~x2|x1+which,data=

 make.groups(dataframe1, dataframe2))


i'd like to replace the labels for dataframe1 and dataframe2 say with
c(A,B). is there a way?

thanks!

On Mon, Oct 27, 2008 at 2:23 PM, Deepayan Sarkar
[EMAIL PROTECTED]wrote:

 On 10/27/08, erwann rogard [EMAIL PROTECTED] wrote:
  hello,
 
   the example below does not work. (i know it's not supposed, but it makes
 it
   clear what i'm trying to achieve)
 
   par(mfrow=c(2,1))
   xyplot(y~x2|x1,data=dataframe1,pch=20)
   xyplot(y~x2|x1,data=dataframe2,pch=20)
 
   i know i could probably merge the two datasets and do something like
   xyplot(y~x2|x1+dataset,data=merged)
 
   any other suggestion?

 xyplot(y~x2|x1+which,data=make.groups(dataframe1, dataframe2))

 -Deepayan


[[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.


[R] Arrays of Trellis plots

2008-10-27 Thread erwann rogard
hello,

the example below does not work. (i know it's not supposed, but it makes it
clear what i'm trying to achieve)

par(mfrow=c(2,1))
xyplot(y~x2|x1,data=dataframe1,pch=20)
xyplot(y~x2|x1,data=dataframe2,pch=20)

i know i could probably merge the two datasets and do something like
xyplot(y~x2|x1+dataset,data=merged)

any other suggestion?

thanks.

[[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] Arrays of Trellis plots

2008-10-27 Thread erwann rogard
Thank you all, I've got everything I need now.

On Mon, Oct 27, 2008 at 2:29 PM, [EMAIL PROTECTED] wrote:

  the example below does not work. (i know it's not supposed, but it makes
 it
  clear what i'm trying to achieve)
 
  par(mfrow=c(2,1))
  xyplot(y~x2|x1,data=dataframe1,pch=20)
  xyplot(y~x2|x1,data=dataframe2,pch=20)
 
  i know i could probably merge the two datasets and do something like
  xyplot(y~x2|x1+dataset,data=merged)

 par is a base graphics command, and doesn't work with grid/lattice
 graphics.  While it is possible to merge grid and base graphics using for
 example the gridBase package, I suspect what you want is to draw two
 lattice plots on the same figure. For this, you need to read up on
 viewports, and try an example like this:

 pushViewport(viewport(layout=grid.layout(2,1)))
 pushViewport(viewport(layout.pos.row=1))
 topplot = xyplot(Sepal.Length ~ Petal.Length | Species, data = iris)
 print(topplot, newpage=FALSE)
 upViewport()
 pushViewport(viewport(layout.pos.row=2))
 bottomplot = xyplot(Sepal.Width ~ Petal.Width | Species, data = iris)
 print(bottomplot, newpage=FALSE)
 popViewport(2)

 See also section 5.5 in Paul Murrell's book ('R Graphics').

 Regards,
 Richie.

 Mathematical Sciences Unit
 HSL


 
 ATTENTION:

 This message contains privileged and confidential information intended
 for the addressee(s) only. If this message was sent to you in error,
 you must not disseminate, copy or take any action in reliance on it and
 we request that you notify the sender immediately by return email.

 Opinions expressed in this message and any attachments are not
 necessarily those held by the Health and Safety Laboratory or any person
 connected with the organisation, save those by whom the opinions were
 expressed.

 Please note that any messages sent or received by the Health and Safety
 Laboratory email system may be monitored and stored in an information
 retrieval system.
 

 
 Scanned by MailMarshal - Marshal's comprehensive email content security
 solution. Download a free evaluation of MailMarshal at www.marshal.com
 


[[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.


[R] Extracting variables with a given prefix in the parent environment

2008-10-20 Thread erwann rogard
hi,

get.vars.name.prefix-function(prefix){
 result-list()
 len-nchar(prefix)
 var.names-ls(name=1,pattern=prefix) #name=1 probably wrong option
 print(var.names)
 for(i in 1:length(var.names)){
  name-var.names[i]
  field-substr(name,len+1,nchar(name))
  result[[field]]-get(name)
 }
 result
}

for example
x.1-1
x.2-2
get.vars.name.prefix(x.) should return 1,2

this does not work if i call if from within another function:

g-function(){
  x.1-1
  x.2-2
  get.vars.name.prefix(x.) # should return 1,2, nothing else
}

i would like the environment specified within ls(...) to be that of the body
of the function that calls get.vars.name.prefix. apparently name=1 is
probably not the right option.

thanks.

[[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] Extracting variables with a given prefix in the parent environment

2008-10-20 Thread erwann rogard
Thank you all for your answers.

On Mon, Oct 20, 2008 at 6:32 AM, Henrique Dallazuanna [EMAIL PROTECTED]wrote:

 Try this:

 Using 'envir' argument, in ls and get function:

 get.vars.name.prefix-function(prefix, envir = parent.frame()){
result-list()
len-nchar(prefix)
var.names-ls(envir = envir,pattern=prefix)
print(var.names)
for(i in 1:length(var.names)){
   name-var.names[i]
   field-substr(name,len+1,nchar(name))
   result[[field]]-get(name, envir = envir)
   }
  result
 }

 On Mon, Oct 20, 2008 at 4:06 AM, erwann rogard [EMAIL PROTECTED]wrote:

 hi,

 get.vars.name.prefix-function(prefix){
  result-list()
  len-nchar(prefix)
  var.names-ls(name=1,pattern=prefix) #name=1 probably wrong option
  print(var.names)
  for(i in 1:length(var.names)){
  name-var.names[i]
  field-substr(name,len+1,nchar(name))
  result[[field]]-get(name)
  }
  result
 }

 for example
 x.1-1
 x.2-2
 get.vars.name.prefix(x.) should return 1,2

 this does not work if i call if from within another function:

 g-function(){
  x.1-1
  x.2-2
  get.vars.name.prefix(x.) # should return 1,2, nothing else
 }

 i would like the environment specified within ls(...) to be that of the
 body
 of the function that calls get.vars.name.prefix. apparently name=1 is
 probably not the right option.

 thanks.

[[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.




 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O


[[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.


[R] passing a list where names arguments are expected

2008-10-19 Thread erwann rogard
hi,

say i have a function f and i'd like to to call it like this:

1) f(list(a=...,b=...))

but i can't do it, because f is defined as:

2) f-function(a=NULL,b=NULL){...}

is there a way that i can approximate 1), such as mapping list(a=,...b=...)
to list(a=,...b=...) and then replacing list by f, and then evaluating
the expression?

thanks.

[[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] passing a list where names arguments are expected

2008-10-19 Thread erwann rogard
Indeed, that's all I need. Thanks!

On Sun, Oct 19, 2008 at 11:09 PM, Kaom Te [EMAIL PROTECTED] wrote:

 I believe you want

 do.call(f, list(a =..., b=...))

 ?do.call
 -Kaom

 On Oct 19, 2008, at 7:55 PM, erwann rogard wrote:

  hi,

 say i have a function f and i'd like to to call it like this:

 1) f(list(a=...,b=...))

 but i can't do it, because f is defined as:

 2) f-function(a=NULL,b=NULL){...}

 is there a way that i can approximate 1), such as mapping
 list(a=,...b=...)
 to list(a=,...b=...) and then replacing list by f, and then
 evaluating
 the expression?

 thanks.

[[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.




[[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] R-code in Latex --- $ sign causes error

2008-10-18 Thread erwann rogard
Haven't tried fancyvrb, but meanwhile this fixes it:

http://www.latex-community.org/viewtopic.php?f=4t=2783p=10955#p10955

On Sat, Oct 18, 2008 at 12:00 AM, Henrik Bengtsson [EMAIL PROTECTED]wrote:

 Check out the 'fancyvrb' latex package - that is quite flexible and I
 wouldn't be surprised if it can help you.  Make sure to read the docs
 (fancyvrb.pdf).

 /H

 On Fri, Oct 17, 2008 at 8:37 PM, erwann rogard [EMAIL PROTECTED]
 wrote:
  Thanks for clarifying. Yes, \$ works in latex, but not *within* the
  lstlisting environment.
 
  On Fri, Oct 17, 2008 at 11:32 PM, Gabor Grothendieck 
  [EMAIL PROTECTED] wrote:
 
  Greg was referring to what to write in R character literals in order to
  generate
  a single \ in the output from R which in turn would be fed into latex or
  Sweave
  and then latex.  Google this: special characters in latex
 
  On Fri, Oct 17, 2008 at 11:23 PM, erwann rogard 
 [EMAIL PROTECTED]
  wrote:
   Thanks, but unfortunately
  
   \begin{lstlisting}
   \\$
   \end{lstlisting}
and
  
   \begin{lstlisting}
   $
   \end{lstlisting}
  
   still generate the same error.
  
  
   On Fri, Oct 17, 2008 at 9:38 PM, Greg Snow [EMAIL PROTECTED]
 wrote:
  
   The $ is special in TeX/LaTeX as a shortcut for beginning/ending
 inline
   math mode, so if you want an actual $ then you need to escape it so
 that
  the
   TeX/LaTeX file has \$ in it.  This means that in your R code that
  generates
   the file you may need \\$ or in some cases $.
  
   Hope this helps,
  
   --
   Gregory (Greg) L. Snow Ph.D.
   Statistical Data Center
   Intermountain Healthcare
   [EMAIL PROTECTED]
   801.408.8111
  
  
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
project.org] On Behalf Of erwann rogard
Sent: Friday, October 17, 2008 5:18 PM
To: r-help@r-project.org
Subject: [R] R-code in Latex --- $ sign causes error
   
hi,
   
here's what i have:
   
\lstset{
  basicstyle=\ttfamily,
  keywordstyle=\bfseries,
  showstringspaces=false,
  columns = fullflexible,
  mathescape = true,
 language=R
}
   
\begin{lstlisting}
lst$val-val
\end{lstlisting}
   
./software.tex:16:Extra }, or forgotten \endgroup. lst$
   
the culprit here is the $ sign.
   
thanks.
   
ps:
   
i'm posting here rather than Latex is bec i guess an R user is more
likely 2
to have encountered this before, but if not ok, pls let me know.
   
[[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.
  
  
  [[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.
  
 
 
 [[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.
 


[[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.


[R] R-code in Latex --- $ sign causes error

2008-10-17 Thread erwann rogard
hi,

here's what i have:

\lstset{
  basicstyle=\ttfamily,
  keywordstyle=\bfseries,
  showstringspaces=false,
  columns = fullflexible,
  mathescape = true,
 language=R
}

\begin{lstlisting}
lst$val-val
\end{lstlisting}

./software.tex:16:Extra }, or forgotten \endgroup. lst$

the culprit here is the $ sign.

thanks.

ps:

i'm posting here rather than Latex is bec i guess an R user is more likely 2
to have encountered this before, but if not ok, pls let me know.

[[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] R-code in Latex --- $ sign causes error

2008-10-17 Thread erwann rogard
Thanks, but unfortunately

\begin{lstlisting}
\\$
\end{lstlisting}
 and

\begin{lstlisting}
$
\end{lstlisting}

still generate the same error.


On Fri, Oct 17, 2008 at 9:38 PM, Greg Snow [EMAIL PROTECTED] wrote:

 The $ is special in TeX/LaTeX as a shortcut for beginning/ending inline
 math mode, so if you want an actual $ then you need to escape it so that the
 TeX/LaTeX file has \$ in it.  This means that in your R code that generates
 the file you may need \\$ or in some cases $.

 Hope this helps,

 --
 Gregory (Greg) L. Snow Ph.D.
 Statistical Data Center
 Intermountain Healthcare
 [EMAIL PROTECTED]
 801.408.8111


  -Original Message-
  From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
  project.org] On Behalf Of erwann rogard
  Sent: Friday, October 17, 2008 5:18 PM
  To: r-help@r-project.org
  Subject: [R] R-code in Latex --- $ sign causes error
 
  hi,
 
  here's what i have:
 
  \lstset{
basicstyle=\ttfamily,
keywordstyle=\bfseries,
showstringspaces=false,
columns = fullflexible,
mathescape = true,
   language=R
  }
 
  \begin{lstlisting}
  lst$val-val
  \end{lstlisting}
 
  ./software.tex:16:Extra }, or forgotten \endgroup. lst$
 
  the culprit here is the $ sign.
 
  thanks.
 
  ps:
 
  i'm posting here rather than Latex is bec i guess an R user is more
  likely 2
  to have encountered this before, but if not ok, pls let me know.
 
  [[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.


[[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] R-code in Latex --- $ sign causes error

2008-10-17 Thread erwann rogard
Thanks for clarifying. Yes, \$ works in latex, but not *within* the
lstlisting environment.

On Fri, Oct 17, 2008 at 11:32 PM, Gabor Grothendieck 
[EMAIL PROTECTED] wrote:

 Greg was referring to what to write in R character literals in order to
 generate
 a single \ in the output from R which in turn would be fed into latex or
 Sweave
 and then latex.  Google this: special characters in latex

 On Fri, Oct 17, 2008 at 11:23 PM, erwann rogard [EMAIL PROTECTED]
 wrote:
  Thanks, but unfortunately
 
  \begin{lstlisting}
  \\$
  \end{lstlisting}
   and
 
  \begin{lstlisting}
  $
  \end{lstlisting}
 
  still generate the same error.
 
 
  On Fri, Oct 17, 2008 at 9:38 PM, Greg Snow [EMAIL PROTECTED] wrote:
 
  The $ is special in TeX/LaTeX as a shortcut for beginning/ending inline
  math mode, so if you want an actual $ then you need to escape it so that
 the
  TeX/LaTeX file has \$ in it.  This means that in your R code that
 generates
  the file you may need \\$ or in some cases $.
 
  Hope this helps,
 
  --
  Gregory (Greg) L. Snow Ph.D.
  Statistical Data Center
  Intermountain Healthcare
  [EMAIL PROTECTED]
  801.408.8111
 
 
   -Original Message-
   From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
   project.org] On Behalf Of erwann rogard
   Sent: Friday, October 17, 2008 5:18 PM
   To: r-help@r-project.org
   Subject: [R] R-code in Latex --- $ sign causes error
  
   hi,
  
   here's what i have:
  
   \lstset{
 basicstyle=\ttfamily,
 keywordstyle=\bfseries,
 showstringspaces=false,
 columns = fullflexible,
 mathescape = true,
language=R
   }
  
   \begin{lstlisting}
   lst$val-val
   \end{lstlisting}
  
   ./software.tex:16:Extra }, or forgotten \endgroup. lst$
  
   the culprit here is the $ sign.
  
   thanks.
  
   ps:
  
   i'm posting here rather than Latex is bec i guess an R user is more
   likely 2
   to have encountered this before, but if not ok, pls let me know.
  
   [[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.
 
 
 [[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.
 


[[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.


[R] Trellis, conditioning on more than 2 variables,

2008-10-13 Thread erwann rogard
hello,

i need help with:

data$f1-as.factor(data$f1)
data$f2-as.factor(data$f2)
s3-equal.count(data$s2,number=3)
densityplot(~y| f1 + f2 + s3,
   data=mydata
)

this produces 3 plots, *successively*, one for each value of s3. i was
hoping it would produce one plot. is trellis limited to 2 conditional
variables? if not, what are the appropriate commands?

thanks!

[[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.