Re: [R] Filling color's points in legend's plot in R

2012-01-19 Thread PtitBleu
Hello Tsidkenu,

Not sure that I have well understood your question but maybe you can add
fill to your legend function :

legend(10,90,legend=c(TR=100 años,TR=50 años,TR=25 años,TR=10
años),lwd=2,pt.cex=1.5,bty='n',pch=c(24,22,21,23),
fill=c(red,green,blue,black))

Have a good day,
Ptit Bleu.


--
View this message in context: 
http://r.789695.n4.nabble.com/Filling-color-s-points-in-legend-s-plot-in-R-tp4308966p4309355.html
Sent from the R help mailing list archive at Nabble.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.


[R] Sweave question - Setting Soutput code chunks to stay inside page margins?

2012-01-19 Thread Tal Galili
Hello all,

Sometimes I get to make an R code chunk (in Sweave) which is longer then
the margins of the page. Is there a way to force it to go to the next
line (in Sweave) once that happens?

Here are two cases this happens in the resulting .tex file (one is a hard
case, and the other is simpler)

\begin{Schunk}
\begin{Sinput}

 print(aa)
\end{Sinput}
\begin{Soutput}
[1] 
aa
\end{Soutput}
\end{Schunk}


\begin{Schunk}
\begin{Soutput}

Some Table

Model 1: SCIM_2_total ~ (I(AMS_2_total^3) + I(AMS_2_total^2) +
AMS_2_total) + fox

Model 2: SCIM_2_total ~ (I(AMS_2_total^2) + AMS_2_total) + fox

\end{Soutput}
\end{Schunk}


I understand this can be fixed from the r side by doing something that
will break lines for outputs, but that will require me to go through any
relevant print command and modify it (I rather find a global solution,
naturally...)


Thanks,
Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--

[[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] Sweave question - Setting Soutput code chunks to stay inside page margins?

2012-01-19 Thread Yihui Xie
Do you have a practical case in which you have to print 114 a's
without spaces? I mean this is such an extreme case that is unlikely
to happen in real life. As long as you have spaces in your string, it
will be easy for LaTeX to wrap long lines, although LaTeX should be
able to do it even if the string does not contain spaces.

Let me add the SO link for future reference as well:
http://stackoverflow.com/q/8907613/559676

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Thu, Jan 19, 2012 at 2:24 AM, Tal Galili tal.gal...@gmail.com wrote:
 Hello all,

 Sometimes I get to make an R code chunk (in Sweave) which is longer then
 the margins of the page. Is there a way to force it to go to the next
 line (in Sweave) once that happens?

 Here are two cases this happens in the resulting .tex file (one is a hard
 case, and the other is simpler)

 \begin{Schunk}
 \begin{Sinput}

 print(aa)
 \end{Sinput}
 \begin{Soutput}
 [1] 
 aa
 \end{Soutput}
 \end{Schunk}


 \begin{Schunk}
 \begin{Soutput}

 Some Table

 Model 1: SCIM_2_total ~ (I(AMS_2_total^3) + I(AMS_2_total^2) +
 AMS_2_total) + fox

 Model 2: SCIM_2_total ~ (I(AMS_2_total^2) + AMS_2_total) + fox

 \end{Soutput}
 \end{Schunk}


 I understand this can be fixed from the r side by doing something that
 will break lines for outputs, but that will require me to go through any
 relevant print command and modify it (I rather find a global solution,
 naturally...)


 Thanks,
 Tal



 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com (English)
 --

        [[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-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] looking for an ecological dataset

2012-01-19 Thread Vito Muggeo (UniPa)

dear all,
apologizes for this off-topic question.

I am looking for a ecological dataset (n100, say) including 
measurements of one or more growth variable and age.


Could anyone to suggest the R package/URL where I can find it?

many thanks,

vito


--

Vito M.R. Muggeo
Dip.to Sc Statist e Matem `Vianelli'
Università di Palermo
viale delle Scienze, edificio 13
90128 Palermo - ITALY
tel: 091 23895240
fax: 091 485726
http://dssm.unipa.it/vmuggeo

__
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] add1 GLM - Warning message, what does it mean?

2012-01-19 Thread Jhope
Hi All, I am wondering if anyone can tell me what the warning message below
the model means? 

J

add1(DTA.glm,~ Aeventexhumed + Veg + Berm + HTL + Estuary + Rayos)
Single term additions

Model:
cbind(MaxHatch, TotalEggs - MaxHatch) ~ Aeventexhumed + Veg + 
Berm + HTL
Df DevianceAIC
none   488.86 4232.9
Estuary  1   454.96 4201.0
Rayos3   258.80 4008.9
Warning messages:
1: In model.matrix.default(Terms, m, contrasts.arg = object$contrasts) :
  variable 'Rayos' converted to a factor
2: In add1.glm(DTA.glm, ~Aeventexhumed + Veg + Berm + HTL + Estuary +  :
  using the 17/83 rows from a combined fit

--
View this message in context: 
http://r.789695.n4.nabble.com/add1-GLM-Warning-message-what-does-it-mean-tp4309553p4309553.html
Sent from the R help mailing list archive at Nabble.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.


[R] Bash script produces: Error in library('package') : there is no package called 'package'

2012-01-19 Thread Leila Lackey
This is a follow-up to a post from 2007:
https://stat.ethz.ch/pipermail/r-help/2007-April/129009.html

Summary of the Problem:

Packages are correctly installed and can be loaded when R is opened
interactively or using a R script. However, a bash scripts produces an
error similar to the following:

#!/bin/bash
...
R --no-save EOF
...
library(package)
Error in library(package) : there is no package called 'package'
Execution halted


At least two workable solutions exist but appear to apply in different
circumstances.

Solution found for the original post:

Multiple versions of R;
R (old): system wide
R (new): on my user side only

When I started R in the command prompt it was calling the R (new) version
because of my .bashrc config. When I was scripting, I was opening a bash
that was by passing some of my config file, thus I was running R (old),
where scatterplot3d was NOT installed.

To solve that I had to make sure I installed only one version of R system
wide and then I had to install the package only once and could use it from
any origin.

To know if you have the same version problem you can save your output of R,
from command and in a script, and look at the version number to see if they
differ. You can also use
 which R
both from the terminal and a script to see if they differ.


If above does not work or only one version of R is installed:

Under some bash scripts, R appears to only look for packages in the
R_LIBS_SITE location (/usr/lib/R/library in this instance), where
base-packages are stored, and does not look for packages in the R_LIBS_USER
location (/home/user/R/*library/2.14 in this instance), where
user-installed packages are stored. Both locations are defined in Renviron.

To work-around, packages can be copied from R_LIBS_SITE to R_LIBS_USER.


Any thoughts or insights would be appreciated. Otherwise, I hope these
work-arounds will be useful to others facing a similar error.

Best,
Leila

[[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] add1 GLM - Warning message, what does it mean?

2012-01-19 Thread Prof Brian Ripley

On Thu, 19 Jan 2012, Jhope wrote:


Hi All, I am wondering if anyone can tell me what the warning message below
the model means?


Which one?: there are two warnings!

1) most likely indicates that Rayos is a character variable.

2) indicates that you have missing values in the variables you are 
trying to add, and so the fits were done on the cases which are 
complete for all the variables included and the AICs are not 
comparable.


Had we had the 'commented, minimal, self-contained, reproducible code' 
we asked you for, this would have been much clearer.




J

add1(DTA.glm,~ Aeventexhumed + Veg + Berm + HTL + Estuary + Rayos)
Single term additions

Model:
cbind(MaxHatch, TotalEggs - MaxHatch) ~ Aeventexhumed + Veg +
   Berm + HTL
   Df DevianceAIC
none   488.86 4232.9
Estuary  1   454.96 4201.0
Rayos3   258.80 4008.9
Warning messages:
1: In model.matrix.default(Terms, m, contrasts.arg = object$contrasts) :
 variable 'Rayos' converted to a factor
2: In add1.glm(DTA.glm, ~Aeventexhumed + Veg + Berm + HTL + Estuary +  :
 using the 17/83 rows from a combined fit

--
View this message in context: 
http://r.789695.n4.nabble.com/add1-GLM-Warning-message-what-does-it-mean-tp4309553p4309553.html
Sent from the R help mailing list archive at Nabble.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.



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] Split values in vector

2012-01-19 Thread Johannes Radinger
Hello,

I have a vector which looks like

x$ART
...
[35415] 0001-1;02-1;05-1;  
[35417] 01-1; 01-1;02-1;   
[35419] 01-1; 00   
[35421] 01-1;04-1;05-1;
[35423] 02-1; 01-1;02-1;   
[35425] 01-1;02-1;NA 
[35427] 01-1; NA
...


This is a vector I got in this format. To explain it:
there are several categories (00,01,02 etc) and its counts (values after -)
So I have to split each value and create new dataframe-columns/vectors
for each categories one column and the value should be then in the
corresponding cell. I know that this vector has 7 categories (00-06)
and NA values but each case (row) has not all the categories (as you can see).  
How can do such as split?

In the end I should get:
x$ART_00, x$ART_01, x$ART_03,... with its values. In the case of NA all the 
categories should have also NA.

Maybe someone can help.

Thank you,

Best regards

Johannes



-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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] Sweave question - Setting Soutput code chunks to stay inside page margins?

2012-01-19 Thread Tal Galili
Hi Yihui,
The a's case happens when, for example, one prints some long equation
function without using spaces in it.  It happened to me in something I
wrote which I will write now while including spaces if I had known it would
solve the issue, but I have yet to have found one (for Sweave, that is :)  )

BTW - I will play with knitr as some point, but I am still looking for
solution within my current toolset.


Tal




Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Thu, Jan 19, 2012 at 10:47 AM, Yihui Xie x...@yihui.name wrote:

 s such an extreme case that is unlikely
 to happen in real life. As long as y


[[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] cacheSweave questions (usage and forward compatibility)

2012-01-19 Thread Tal Galili
Hello all,

I would like to ask several questions regarding cacheSweave:
1) Is there a way to set cache=true globally? (I tried it
using \SweaveOpts but it didn't seem to work)
 2) Is there a way to flush specific cache once it is created? (other
then erasing the entire cache directory)?  Changing the code in the code
chunk seems to do it, but I am not sure to what extent.  For example - if I
add at the end of the code chunk a number (say 1 - that will be printed),
it will reevaluate the code chunk.  However, if I remove that number, it
will not re-evaluate the code chunk.
3) To what extent does cacheSweave rely on Sweave? For example: I see that
the latest Sweave document is from October 31, 2011 while the latest update
to cacheSweave is from 2011-07-23.  Does that mean that there are new
features or bug fixes that are introduced to Sweave which are not available
through cacheSweave?  (from the manual it says that cacheSweave is based on
the code version of R 2.5.0.  What does that mean in terms of
features/bugs?)

Thank you for your help,
Tal







Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--

[[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] Not generating line chart

2012-01-19 Thread Jan van der Laan

Devarayalu,

This is FAQ 7.22:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f

use print(qplot())

Regards,
Jan


Sri krishna Devarayalu Balanagu balanagudevaray...@gvkbio.com schreef:


Hi All,


Can you please help me, why this code in not generating line chart?



library(ggplot2)
par(mfrow=c(1,3))

#qplot(TIME1, BASCHGA, data=Orange1, geom= c(point, line),  
colour= ACTTRT)

unique(Orange1$REFID) - refid
for (i in refid)
{
Orange2 - Orange1[i == Orange1$REFID, ]
pdf('PGA.pdf')
qplot(TIME1, BASCHGA, data=Orange2, geom= c(line), colour= ACTTRT)
dev.off()
}
Regards,
Devarayalu

[[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-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] Bash script produces: Error in library('package') : there is no package called 'package'

2012-01-19 Thread Petr Savicky
On Thu, Jan 19, 2012 at 12:13:00AM -0800, Leila Lackey wrote:
 This is a follow-up to a post from 2007:
 https://stat.ethz.ch/pipermail/r-help/2007-April/129009.html
 
 Summary of the Problem:
 
 Packages are correctly installed and can be loaded when R is opened
 interactively or using a R script. However, a bash scripts produces an
 error similar to the following:
 
 #!/bin/bash
 ...
 R --no-save EOF
 ...
 library(package)
 Error in library(package) : there is no package called 'package'
 Execution halted
 
 
 At least two workable solutions exist but appear to apply in different
 circumstances.
 
 Solution found for the original post:
 
 Multiple versions of R;
 R (old): system wide
 R (new): on my user side only
 
 When I started R in the command prompt it was calling the R (new) version
 because of my .bashrc config. When I was scripting, I was opening a bash
 that was by passing some of my config file, thus I was running R (old),
 where scatterplot3d was NOT installed.
 
 To solve that I had to make sure I installed only one version of R system
 wide and then I had to install the package only once and could use it from
 any origin.

In a bash script, it is also possible to run R using a full path to
its R-version/bin/R. This path may possibly include $HOME, which
should be the same in a bash script and in an interactive bash.
In this case, the $PATH variable, which may differ, is not used.

 To know if you have the same version problem you can save your output of R,
 from command and in a script, and look at the version number to see if they
 differ.

In a situation, when the same version is installed in different
directories, they may be distinguished by printing the variable

  .Library

which prints the directory, where R is installed, with an
additional /library.

Petr Savicky.

__
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] New PLYR issue

2012-01-19 Thread Gunnar Oehmichen

Hi,

thanks a lot. That was quite helpful, not only in terms of providing a 
solution to my problem, but in terms of efficiently explaining, what the 
problem is about.


On 17/01/2012 18:26, Jeff Newmiller wrote:
Replying to old messages without including context (particularly old 
ones) is rather bad netiquette.


Thank you for at least providing a reproducible example. Now if you 
can figure out how to read the documentation we will really make some 
progress.


Further responses below.

On Tue, 17 Jan 2012, Gunnar Oehmichen wrote:



Hello everyone,

I have got the same problem, with the same error message.


I wasn't able to draw a comparison between the problems, though the 
error messages were the same.



Using R 2.14.1, plyr 1.7.1, R.Studio 0.94.110, Windows XP

The plyr mailing list does not provide any help until now.

require(plyr)

c(sample(c(1:100), 50, replace=TRUE))-V1


Much better to use  -  than - for clarity of code (spaces and 
direction of assignment make a difference for readability)



c(rep( 1:5, 10))-f1 #variable to group V1

data.frame(cbind(V1, f1))-DF

str(DF)

ddply(DF$V1, DF$f1, sd)
ddply(.(DF$V1), .(DF$f1), sd)

Error in if (empty(.data)) return(.data) :
missing value where TRUE/FALSE needed

Thanks everyone,


If you hand a toothpick to a mechanic you should not be surprised when 
he tells you he cannot change a tire from your car.  You are giving a 
vector where a data frame is needed, another vector where a name or 
vector of names are required, and the name of a function where an 
actual function is needed, and the function is complaining. In the 
face of such confusion, it is not surprising that people were unable 
to figure out where to start setting you straight.  However, in return 
for your reproducible example I will give it a go.


A basic unifying concept for the plyr package is that the name of the 
function tells you something about what needs to go in, and what will 
come out. ddply starts with a d so it expects a data frame as 
input, and because the second letter is also a d it will yield a 
data frame result when it is done.


Argument 1:

DF$V1 is a vector. It happens to be the the column named V1 in the 
data frame DF.  To specify a data frame, don't apply operators to it, 
just write the name of the data frame DF.


Argument 2:

This argument tells ddply what the name of the grouping columns are. 
Do not actually give the grouping columns to ddply (which $ does).  I 
have found that while the .() function seems cleaner, I find it 
clearer to use a vector of strings ... in this case, there is only one 
grouping column, so I would forego the usual c() concatenator and just 
give it f1.


Argument 3:

This argument is supposed to be a function that will take a data frame 
(first d) and yield a data frame (second d) for one group of rows.  
ddply will take care of stacking them as a single data frame for the 
final result.  You have given ddply the name (first error) of a 
function that takes a vector and returns a scalar (wrong type of 
function is error two).


The correct documentation for all of these arguments can be found by 
typing ?ddply at the R command line (after you have loaded plyr).  It 
looks like you have been reading the documentation for ?aggregate or 
?summaryBy (doBy package) and trying to use that to inform your use of 
ddply.


So the actual call should be:


ddply(DF,f1,function(df){data.frame(sdV1=sd(df$V1))})

  f1 sdV1
1  1 19.93016
2  2 35.96356
3  3 33.30349
4  4 26.62831
5  5 25.03087

In general, to add more simultaneous calculations, you add more 
columns to the data frame produced by your function that does the 
calculations. If you want to give it a function name, don't put it in 
quotes:



myfunction - function(df){

+  data.frame(sdV1=sd(df$V1),meanV1=mean(df$V1))
+ }

ddply(DF,f1,myfunction)

  f1 sdV1 meanV1
1  1 19.93016   49.1
2  2 35.96356   45.6
3  3 33.30349   44.7
4  4 26.62831   72.2
5  5 25.03087   30.1

Note that although ddply does a lot for you, it doesn't reproduce all 
of your calculations on all of the data columns like summaryBy does... 
you have to explicitly create every calculated column in your function.


--- 

Jeff NewmillerThe .   .  Go 
Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live 
Go...

  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  
rocks...1k
--- 




--


Gunnar Oehmichen / Diploma Student of Environmental Sciences
Department of Conservation Biology


Re: [R] Not generating line chart

2012-01-19 Thread Jan van der Laan

Devarayalu,

Please reply to the list.

And it would have easier if you would have outputted your data using  
dput (in your case dput(Orange1)) so that I and other r-help members  
can just copy the data into R. Not everybody had Excell available (I  
for example haven't). The easier you make it for people to look into  
your problem, the higher the probability that you will get a usefull  
answer. In your case your data is quite small, so using dput is no  
problem.


To answer your question. Except for the probable error

refid - unique(Orange2$REFID)

which should probably be

refid - unique(Orange1$REFID)

and the fact that overwrite your files in the loop, I have no problem  
generating the graphs. On my system the following code runs and  
generates two graphs:



library(ggplot2)

Orange1 - structure(list(REFID = c(7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 9L,
9L, 9L, 9L), ARM = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L,
2L, 2L), SUBARM = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L), ACTTRT = structure(c(3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 1L,
1L, 2L, 2L), .Label = c(ABC, DEF, LCD, Vehicle), class = factor),
TIME1 = c(0L, 2L, 6L, 12L, 0L, 2L, 6L, 12L, 0L, 12L, 0L,
12L), ENDPOINT = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L), .Label = PGA, class = factor), BASCHGA = c(0L,
-39L, -47L, -31L, 0L, -34L, -25L, -12L, 0L, -30L, 0L, -40L
), STATANAL = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), .Label = UNK, class = factor), X = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c(,
Dansinger_2010_20687812), class = factor)), .Names = c(REFID,
ARM, SUBARM, ACTTRT, TIME1, ENDPOINT, BASCHGA, STATANAL,
X), class = data.frame, row.names = c(NA, -12L))

refid - unique(Orange1$REFID)
for (i in refid)
{
  Orange2 - Orange1[i == Orange1$REFID, ]
  pdf(paste('PGA', i, '.pdf', sep=''))
  print(qplot(TIME1, BASCHGA, data=Orange2, geom= c(line), colour= ACTTRT))
  dev.off()
}



Regards,
Jan



Sri krishna Devarayalu Balanagu balanagudevaray...@gvkbio.com schreef:


Jan

Thank you, for your valuable reply. But...

Sorry still I am not getting by using print() with the following  
modified code. I am also attaching the raw datafile.



par(mfrow=c(1,3))

#qplot(TIME1, BASCHGA, data=Orange1, geom= c(point, line),  
colour= ACTTRT)

unique(Orange1$REFID) - refid
for (i in refid)
{
Orange2 - Orange1[i == Orange1$REFID, ]
pdf('PGA.pdf')
print(qplot(TIME1, BASCHGA, data=Orange2, geom= c(line), colour= ACTTRT))
dev.off()
}
Regards
Devarayalu





-Original Message-
From: Jan van der Laan [mailto:rh...@eoos.dds.nl]
Sent: Thursday, January 19, 2012 4:25 PM
To: Sri krishna Devarayalu Balanagu
Cc: r-help@r-project.org
Subject: Re: [R] Not generating line chart

Devarayalu,

This is FAQ 7.22:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f

use print(qplot())

Regards,
Jan


Sri krishna Devarayalu Balanagu balanagudevaray...@gvkbio.com schreef:


Hi All,


Can you please help me, why this code in not generating line chart?



library(ggplot2)
par(mfrow=c(1,3))

#qplot(TIME1, BASCHGA, data=Orange1, geom= c(point, line),
colour= ACTTRT)
unique(Orange1$REFID) - refid
for (i in refid)
{
Orange2 - Orange1[i == Orange1$REFID, ]
pdf('PGA.pdf')
qplot(TIME1, BASCHGA, data=Orange2, geom= c(line), colour= ACTTRT)
dev.off()
}
Regards,
Devarayalu

[[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-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] Split values in vector

2012-01-19 Thread Gerrit Eichner

Hi, Johannes,

maybe

X - unlist( strsplit( as.character( x$ART), split = ;, fixed = TRUE))
X - strsplit( X, split = -, fixed = TRUE)

X - sapply( X, function( x)
 if( length(x) == 2)
  rep( x[1], as.numeric( x[2])) else x[1]
)

table(X, useNA = always)


comes close to what you want.

 Hth  --  Gerrit


On Thu, 19 Jan 2012, Johannes Radinger wrote:


Hello,

I have a vector which looks like

x$ART
...



[35415] 0001-1;02-1;05-1;
[35417] 01-1; 01-1;02-1;
[35419] 01-1; 00
[35421] 01-1;04-1;05-1;
[35423] 02-1; 01-1;02-1;
[35425] 01-1;02-1;NA
[35427] 01-1; NA
...


This is a vector I got in this format. To explain it:
there are several categories (00,01,02 etc) and its counts (values after -)
So I have to split each value and create new dataframe-columns/vectors
for each categories one column and the value should be then in the
corresponding cell. I know that this vector has 7 categories (00-06)
and NA values but each case (row) has not all the categories (as you can see).  
How can do such as split?

In the end I should get:
x$ART_00, x$ART_01, x$ART_03,... with its values. In the case of NA all the 
categories should have also NA.

Maybe someone can help.

Thank you,

Best regards

Johannes



--
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

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


[R] nls issue

2012-01-19 Thread Mathew Brown

Hello,

I'm trying to make a non-linear regression using the attached data and 
this model. When I run it I get the following message:


Error in nls(y ~ 1/(a + w * x), data = df, start = list(a = 1, w = 1),  :
  singular gradient



mod - nls(y~1/(a+w*x),data=df,start=list(a=1,w=1),trace = TRUE)


Any idea what the problem is?

Cheers,
Mat

__
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] What does the : operator mean in glm formulas

2012-01-19 Thread Xiaobo Gu
Hi,

I see the following is the credit scoreing in R guide :

m2-glm(formula = good_bad ~ checking + duration + history+ purpose +amount + 
savings + employed + installp + marital +
coapp +age + other + depends + telephon + foreign +checking:amount

What does checking:amount mean?

Regards,

Xiaobo Gu
__
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] Problems with Panel Data estimation

2012-01-19 Thread JBrettas
Anyone? ):

--
View this message in context: 
http://r.789695.n4.nabble.com/Problems-with-Panel-Data-estimation-tp4306602p4309813.html
Sent from the R help mailing list archive at Nabble.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] add1 GLM - Warning message, what does it mean?

2012-01-19 Thread Jhope
Thank you Prof Ripley, I understand and changed Rayos into a factor. 

Can someone please tell me how to change the: 

Model: 
 cbind(MaxHatch, TotalEggs - MaxHatch) ~ Aeventexhumed + Veg + 
Berm + HTL 

Into a model that has?: 

Model:
cbind(MaxHatch, TotalEggs - MaxHatch) ~ 1

Best, J

--
View this message in context: 
http://r.789695.n4.nabble.com/add1-GLM-Warning-message-what-does-it-mean-tp4309553p4309632.html
Sent from the R help mailing list archive at Nabble.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.


[R] Legend problem in line charts

2012-01-19 Thread Sri krishna Devarayalu Balanagu

Hi all,

Small problem in generating the line charts.

Question: Legend for the first graph is coming wrong.,  for second graph 
correctly.  Please fix the legend postion at the down of graph.
Plesae give me the solution.

Thank you
Devarayalu



Orange1 - structure(list(REFID = c(7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
8, 8, 8, 8, 9, 9, 9, 9), ARM = c(1, 1, 1, 1, 2, 2, 2, 2, 1, 1,
1, 1, 2, 2, 2, 2, 1, 1, 2, 2), SUBARM = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ACTTRT = structure(c(3L,
3L, 3L, 3L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L,
1L, 2L, 2L), .Label = c(ABC, DEF, LCD, Vehicle), class = factor),
TIME1 = c(0, 2, 6, 12, 0, 2, 6, 12, 0, 2, 6, 12, 0, 2, 6,
12, 0, 12, 0, 12), ENDPOINT = structure(c(1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), .Label = PGA, class = factor), BASCHGA = c(0, -39,
-47, -31, 0, -34, -25, -12, 0, -45, -47, -20, 0, -25, -30,
-35, 0, -30, 0, -40), STATANAL = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = UNK, class = factor), Art_Name = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L), .Label = c(Bela_2010_206878, Dansinger_2010_20687812
), class = factor)), .Names = c(REFID, ARM, SUBARM,
ACTTRT, TIME1, ENDPOINT, BASCHGA, STATANAL, Art_Name
), row.names = c(NA, 20L), class = data.frame)


unique(Orange1$REFID) - refid
# Create Line Chart
for (i in 1:length(refid)) {
# convert factor to numeric for convenience
refid1 - subset(Orange1, REFID == refid[i])
refid1$ACTTRTnum - as.numeric(refid1$ACTTRT)
nACTTRTs - max(refid1$ACTTRTnum)

# get the range for the x and y axis
xrange - range(refid1$TIME1)
yrange - range(refid1$BASCHGA)

# set up the plot
pdf (paste(pga, i, .pdf, sep=''))
print(plot(xrange, yrange, type=n, xlab=TIME1 (WK),
   ylab=BASCHGA (mm) ))
colors - rainbow(nACTTRTs)
linetype - c(1:nACTTRTs)
plotchar - seq(18,18+nACTTRTs,1)

# add lines

for (i in 1:nACTTRTs) {
  ACTTRT - subset(refid1, ACTTRTnum==i)
  print(lines(ACTTRT$TIME1, ACTTRT$BASCHGA, type=b, lwd=1.5,
lty=linetype[i], col=colors[i], pch=plotchar[i]))
}

# add a title and subtitle
paste(REFID = , unique(refid1$REFID), ; STATANAL = , 
unique(refid1$STATANAL), sep=) - x
title(x)


# add a legend
legend(xrange[1], yrange[2], unique(refid1$ACTTRT), cex=0.8, col=colors,
   pch=plotchar, lty=linetype)
#bottomright, bottom, bottomleft, left, topleft, top, topright, 
right and center
dev.off()
}


[[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] Sweave question - Setting Soutput code chunks to stay inside page margins?

2012-01-19 Thread Duncan Murdoch

On 12-01-19 3:24 AM, Tal Galili wrote:

Hello all,

Sometimes I get to make an R code chunk (in Sweave) which is longer then
the margins of the page. Is there a way to force it to go to the next
line (in Sweave) once that happens?


Sweave normally uses a verbatim environment, so you have to arrange this 
on the R side.  Setting options(width=60) works in a lot of cases, but 
not in your example below.


Duncan Murdoch



Here are two cases this happens in the resulting .tex file (one is a hard
case, and the other is simpler)

\begin{Schunk}
\begin{Sinput}


print(aa)

\end{Sinput}
\begin{Soutput}
[1] 
aa
\end{Soutput}
\end{Schunk}


\begin{Schunk}
\begin{Soutput}

Some Table

Model 1: SCIM_2_total ~ (I(AMS_2_total^3) + I(AMS_2_total^2) +
AMS_2_total) + fox

Model 2: SCIM_2_total ~ (I(AMS_2_total^2) + AMS_2_total) + fox

\end{Soutput}
\end{Schunk}


I understand this can be fixed from the r side by doing something that
will break lines for outputs, but that will require me to go through any
relevant print command and modify it (I rather find a global solution,
naturally...)


Thanks,
Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--

[[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-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] Mean of simulation runs given in a table

2012-01-19 Thread Irek Szczesniak
Thank you, William, for your help!  It works great.  My final call
looks like this:

pars - c(.(nodes), .(load), .(buffer), .(deflections))
ddply(i, pars, summarize,
 mm_created = mean(mean_created),
 ms_created = mean(sdev_created),
 mm_admitted = mean(mean_admitted),
 ms_admitted = mean(sdev_admitted),
 mm_dropped = mean(mean_dropped),
 ms_dropped = mean(sdev_dropped),
 mm_delivered = mean(mean_delivered),
 ms_delivered = mean(sdev_delivered))

2012/1/18 William Dunlap wdun...@tibco.com:
 Try using the function in the plyr package.  E.g.,
   z - data.frame( # your toy dataset
       run = c(1, 2, 1, 2),
       par = c(10, 10, 20, 20),
       measured = c(12, 14, 20, 26))
   library(plyr)
   ddply(z, .(par), summarize, meanMeasured=mean(measured), 
 sdMeasured=sd(measured))
    par meanMeasured sdMeasured
  1  10           13 1.414214
  2  20           23 4.242641

 Bill Dunlap
 Spotfire, TIBCO Software
 wdunlap tibco.com

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of Ireneusz
 Szczesniak
 Sent: Tuesday, January 17, 2012 2:43 PM
 To: r-help@r-project.org
 Subject: Re: [R] Mean of simulation runs given in a table

 Thank you, Uwe, for your help!  I have more measurements (m1, m2) and
 more parameters (par1, par2).  I can calculate the means of m1 and m2
 this way:

 aggregate(cbind(m1, m2) ~ par1 + par2, dat, mean)

 However, I also need to calculate the standard error of the mean, and
 the variance for the sample, and I would like to have them output as
 extra columns next to the column with means.

 Again, I would appreciate any help!

 On 17.01.2012 15:09, Uwe Ligges wrote:
 
 
  On 17.01.2012 12:31, Irek Szczesniak wrote:
  Hi,
 
  I have the simulation results of the following structure:
 
  run par measured
  1 10 12
  2 10 14
  1 20 20
  2 20 26
 
  Where run is the simulation run number, par is the parameter of
  the simulation, and measured is the value measured in the
  simulation. This is only a simple example of my results. There are
  many values measured and many parameters. But the basic structure
  stays the same: there are many runs (identified by the run number) for
  the same values of the parameters with various measured values -- they
  constitute a sample.
 
  I would like to calculate the mean of the measured value for a
  sample, and so I would like to obtain the output as follows:
 
  par mean
  10 13
  20 23
 
  I would appreciate it if someone could write me how to do it.
 
 
  For you data in a data.frame called dat:
 
  aggregate(measured ~ par, dat, mean)
 
  Uwe Ligges
 
 
 
  Thank you,
  Irek
 
  __
  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.
 


 --
 Ireneusz (Irek) Szczesniak
 http://www.irkos.org

 __
 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] Not generating line chart

2012-01-19 Thread Jan van der Laan
As I mentioned in my previous reply: do not only email to me  
personally but also include the mailinglist. This gives other members  
also the opportunity to answer your question and lets other members,  
who might have a similar question, also see the answer.


As for your first question: put the pdf(...) and dev.off() outside of  
the loop. I am not an ggplot2 expert, but you could also have a look  
at the facets option of qplot.


As for your second question: have a look at
levels(Orange1$ACTTRT)
and
?factor

Regards,
Jan


Sri krishna Devarayalu Balanagu balanagudevaray...@gvkbio.com schreef:


Jan,

Thank you very much for the solution given. Still I am having one  
more question.


I want both the graphs in single pdf and the legend should contain  
ACTTRT of individual REFID (Only two lines in legend)

Can you solve it?

Devarayalu


-Original Message-
From: Jan van der Laan [mailto:rh...@eoos.dds.nl]
Sent: Thursday, January 19, 2012 5:09 PM
To: Sri krishna Devarayalu Balanagu
Cc: r-help@r-project.org
Subject: Re: [R] Not generating line chart

Devarayalu,

Please reply to the list.

And it would have easier if you would have outputted your data using
dput (in your case dput(Orange1)) so that I and other r-help members
can just copy the data into R. Not everybody had Excell available (I
for example haven't). The easier you make it for people to look into
your problem, the higher the probability that you will get a usefull
answer. In your case your data is quite small, so using dput is no
problem.

To answer your question. Except for the probable error

refid - unique(Orange2$REFID)

which should probably be

refid - unique(Orange1$REFID)

and the fact that overwrite your files in the loop, I have no problem
generating the graphs. On my system the following code runs and
generates two graphs:


library(ggplot2)

Orange1 - structure(list(REFID = c(7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 9L,
9L, 9L, 9L), ARM = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L,
2L, 2L), SUBARM = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L), ACTTRT = structure(c(3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 1L,
1L, 2L, 2L), .Label = c(ABC, DEF, LCD, Vehicle), class = factor),
 TIME1 = c(0L, 2L, 6L, 12L, 0L, 2L, 6L, 12L, 0L, 12L, 0L,
 12L), ENDPOINT = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L), .Label = PGA, class = factor), BASCHGA = c(0L,
 -39L, -47L, -31L, 0L, -34L, -25L, -12L, 0L, -30L, 0L, -40L
 ), STATANAL = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L), .Label = UNK, class = factor), X = structure(c(1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c(,
 Dansinger_2010_20687812), class = factor)), .Names = c(REFID,
ARM, SUBARM, ACTTRT, TIME1, ENDPOINT, BASCHGA, STATANAL,
X), class = data.frame, row.names = c(NA, -12L))

refid - unique(Orange1$REFID)
for (i in refid)
{
   Orange2 - Orange1[i == Orange1$REFID, ]
   pdf(paste('PGA', i, '.pdf', sep=''))
   print(qplot(TIME1, BASCHGA, data=Orange2, geom= c(line),  
colour= ACTTRT))

   dev.off()
}



Regards,
Jan



Sri krishna Devarayalu Balanagu balanagudevaray...@gvkbio.com schreef:


Jan

Thank you, for your valuable reply. But...

Sorry still I am not getting by using print() with the following
modified code. I am also attaching the raw datafile.


par(mfrow=c(1,3))

#qplot(TIME1, BASCHGA, data=Orange1, geom= c(point, line),
colour= ACTTRT)
unique(Orange1$REFID) - refid
for (i in refid)
{
Orange2 - Orange1[i == Orange1$REFID, ]
pdf('PGA.pdf')
print(qplot(TIME1, BASCHGA, data=Orange2, geom= c(line), colour= ACTTRT))
dev.off()
}
Regards
Devarayalu





-Original Message-
From: Jan van der Laan [mailto:rh...@eoos.dds.nl]
Sent: Thursday, January 19, 2012 4:25 PM
To: Sri krishna Devarayalu Balanagu
Cc: r-help@r-project.org
Subject: Re: [R] Not generating line chart

Devarayalu,

This is FAQ 7.22:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f

use print(qplot())

Regards,
Jan


Sri krishna Devarayalu Balanagu balanagudevaray...@gvkbio.com schreef:


Hi All,


Can you please help me, why this code in not generating line chart?



library(ggplot2)
par(mfrow=c(1,3))

#qplot(TIME1, BASCHGA, data=Orange1, geom= c(point, line),
colour= ACTTRT)
unique(Orange1$REFID) - refid
for (i in refid)
{
Orange2 - Orange1[i == Orange1$REFID, ]
pdf('PGA.pdf')
qplot(TIME1, BASCHGA, data=Orange2, geom= c(line), colour= ACTTRT)
dev.off()
}
Regards,
Devarayalu

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

Re: [R] Table Intersection

2012-01-19 Thread rantree
thank you a lot :)

--
View this message in context: 
http://r.789695.n4.nabble.com/Table-Intersection-tp4306968p4309929.html
Sent from the R help mailing list archive at Nabble.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.


[R] converting a for loop into a foreach loop

2012-01-19 Thread kalee
Dear all,

Just wondering if someone could help me out converting my code from a for()
loop into a foreach() loop or using one of the apply() function. I have a
very large dataset and so I'm hoping to make use of a parallel backend to
speed up the processing time. I'm having trouble getting selecting three
variables in the dataset to use in the foreach() loops. My for() loop code
is:

library(foreach)
library(multicore)
library(doMC)
registerDoMC()


 str(data)
'data.frame':   958 obs. of  13 variables:
 $ Date.Time: Factor w/ 260 levels 03/07/09 00:00,..: 1 2 2 2 3 3 3 3 3 3
...
 $ ID   : int  3 1 3 7 1 3 7 8 10 12 ...
 $ X: num  151 151 151 151 151 ...
 $ Y: num  -33.9 -33.9 -33.9 -33.9 -33.9 ...
 $ Z: num  8 8 8 12 8 8 10 8 8 4 ...
 $ breeding : int  1 1 1 1 1 1 1 1 1 1 ...
 $ hour : int  0 0 0 0 0 0 0 0 0 0 ...
 $ sex  : Factor w/ 4 levels ,F,M,U: 3 4 3 4 4 3 4 3 2 4 ...
 $ sex.code : int  1 3 1 3 3 1 3 1 2 3 ...
 $ day  : int  39997 39997 39997 39997 39997 39997 39997 39997 39997
39997 ...
 $ hour1: int  24 24 24 24 24 24 24 24 24 24 ...
 $ X1   : num  1765688 1765492 1765492 1765637 1765383 ...
 $ Y1   : num  -3834667 -3834964 -3834964 -3834786 -3834990 ...


for (i in 1:15) {

x = data[data$ID == i, 1:10]

  for (j in 1:length(x$day)) {

  y = x[x$day == j, 1:10]

 for (k in 1:length(y$hour1)) {

z = y[y$hour1 == k, 1:10]

   
H.scv - Hscv(z, pilot = unconstr)

KDE - kde(z, H=H.scv, approx.cont=TRUE)
str(KDE)
head(KDE)

write.csv(KDE, file = paste(KDE,i j k,.csv), row.names=T)

}
}
}

The foreach code I've tried (unsuccessfully) is:

x - foreach(a = data[, 'ID'], .combine = rbind) %:% foreach(b = data[ ,
'day'], .combine = cbind) %:% foreach[c = data['hour1'], .combine
=cbind] %dopar% {
   
   
H.scv - Hscv((a,b,c), pilot = unconstr)

KDE - kde((a,b,c), H=H.scv, approx.cont=TRUE)
str(KDE)
head(KDE)

write.csv(KDE, file = paste(KDE,i,.csv), row.names=T)

}

Many thanks for any help. 



--
View this message in context: 
http://r.789695.n4.nabble.com/converting-a-for-loop-into-a-foreach-loop-tp4309646p4309646.html
Sent from the R help mailing list archive at Nabble.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] What does the : operator mean in glm formulas

2012-01-19 Thread Ted Harding
On 19-Jan-2012 Xiaobo Gu wrote:
 Hi,
 I see the following is the credit scoreing in R guide :
 
 m2-glm(formula = good_bad ~ checking + duration + history +
 purpose +amount + savings + employed + installp + marital +
 coapp +age + other + depends + telephon + foreign +checking:amount
 
 What does checking:amount mean?
 
 Regards,
 Xiaobo Gu

See the explanation of model formulae under Details in ?glm :

  A specification of the form ?first:second? indicates
  the set of terms obtained by taking the interactions
  of all terms in 'first' with all terms in 'second'.
  The specification 'first*second' indicates the _cross_
  of 'first' and 'second'.
  This is the same as 'first + second + first:second'.

Ted.

-
E-Mail: (Ted Harding) ted.hard...@wlandres.net
Date: 19-Jan-2012  Time: 13:37:23
This message was sent by XFMail

__
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] What does the : operator mean in glm formulas

2012-01-19 Thread David Winsemius


On Jan 19, 2012, at 8:02 AM, Xiaobo Gu wrote:


Hi,

I see the following is the credit scoreing in R guide :

m2-glm(formula = good_bad ~ checking + duration + history+ purpose  
+amount + savings + employed + installp + marital +

coapp +age + other + depends + telephon + foreign +checking:amount

What does checking:amount mean?


?formula

--

David Winsemius, MD
West Hartford, CT

__
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] cacheSweave questions (usage and forward compatibility)

2012-01-19 Thread Ben Bolker
Tal Galili tal.galili at gmail.com writes:

 
 Hello all,
 
 I would like to ask several questions regarding cacheSweave:
 1) Is there a way to set cache=true globally? (I tried it
 using \SweaveOpts but it didn't seem to work)
  2) Is there a way to flush specific cache once it is created? (other
 then erasing the entire cache directory)?  Changing the code in the code
 chunk seems to do it, but I am not sure to what extent.  For example - if I
 add at the end of the code chunk a number (say 1 - that will be printed),
 it will reevaluate the code chunk.  However, if I remove that number, it
 will not re-evaluate the code chunk.
 3) To what extent does cacheSweave rely on Sweave? For example: I see that
 the latest Sweave document is from October 31, 2011 while the latest update
 to cacheSweave is from 2011-07-23.  Does that mean that there are new
 features or bug fixes that are introduced to Sweave which are not available
 through cacheSweave?  (from the manual it says that cacheSweave is based on
 the code version of R 2.5.0.  What does that mean in terms of
 features/bugs?)-

  I hope you get an answer here, but especially the last question
seems appropriate for the package maintainer.
  I'm enthusiastic about knitr, it seems to solve a lot of the frustrations
I was having trying to get all the (reliable) features I wanted from 
the combination of {Sweave, cacheSweave,  pgfSweave, weaver} ...

__
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 help: source-function is very slow

2012-01-19 Thread Jos van Nijnatten
Hello everybody,
I noticed a performance problem when using the source-function in R. 
When I try to source an r script that is located in the same directory 
as the script I execute via command line ('R -f file.r' contents 
'source(someOtherScript.r)') it's very fast. But if I put 
'someOtherScript.r' in another directory (say ../../R) R takes moments, 
if not minutes to locate and load the script. Is there another way to do 
this that is not slow?
Thanks, Jos

-- 
Jos van Nijnatten, BSc Candidate
Erasmus MC, Rotterdam, NL
Department of Bioinformatics
(ph) +31 1 07 04 45 51
(mob) +31 6 14 92 14 01
(e) j.vannijnat...@erasmusmc.nl

[[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] Interpreting script - write.csv

2012-01-19 Thread David Winsemius


On Jan 18, 2012, at 10:48 PM, Jhope wrote:


Hi All,

I am a beginner to R and a prof helped me with some script. I am  
having

trouble understanding the below line. Is it finding the file
turtlehatch.csv? I do not have my working directory set to this  
file. If so

I tried (file.choose) and it did not work.


I don't think you can use file.choose() to create a new file for output.


R did nothing in response, no
error message with this entry and the below entry.


It probably _did_ work. Generally R will report errors to the  
console.  You just don't know where to find it because it went to your  
working directory. Try this to find where it went:


getwd()



Can you please help me interpret? :

write.csv(data.to.analyze, turtlehatch.csv, row.names=FALSE)

Thanks,  J

--
View this message in context: 
http://r.789695.n4.nabble.com/Interpreting-script-write-csv-tp4309068p4309068.html
Sent from the R help mailing list archive at Nabble.com.


R-help is not _at_ Nabble. And Nabble is _not_ rhelp's archive.

--

David Winsemius, MD
West Hartford, CT

__
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] What does the : operator mean in glm formulas

2012-01-19 Thread Xiaobo Gu
Such a model consists of a series of terms separated by +operators. 
In the above ,term means individual variable.

The terms themselves consist of variable and factor names separated by : 
operators. 
What does term mean in this?

Such a term is interpreted as the interaction of all the variables and factors 
appearing in the term.

What does interaction mean, and what does term mean here ?






Xiaobo Gu

From: David Winsemius
Date: 2012-01-19 21:46
To: guxiaobo1982
CC: r-help; ds5j
Subject: Re: [R] What does the : operator mean in glm formulas

On Jan 19, 2012, at 8:02 AM, Xiaobo Gu wrote:

 Hi,

 I see the following is the credit scoreing in R guide :

 m2-glm(formula = good_bad ~ checking + duration + history+ purpose  
 +amount + savings + employed + installp + marital +
 coapp +age + other + depends + telephon + foreign +checking:amount

 What does checking:amount mean?

?formula

-- 

David Winsemius, MD
West Hartford, CT
__
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] What does the : operator mean in glm formulas

2012-01-19 Thread David Winsemius


On Jan 19, 2012, at 8:56 AM, Xiaobo Gu wrote:


Such a model consists of a series of terms separated by +operators.

In the above ,term means individual variable.

The terms themselves consist of variable and factor names separated  
by : operators.

What does term mean in this?

Such a term is interpreted as the interaction of all the variables  
and factors appearing in the term.


What does interaction mean, and what does term mean here ?



I'm sorry. This is the wrong list to request tutoring in basic  
statistics. If you don't know what an interaction is, it suggests that  
you do not have sufficient education to safely use R or any other  
statistics package for that matter. You should go back to any basic  
regression textbook (or perhaps do a web-search) and do sufficient  
self-study to answer that question.


--
David.



Xiaobo Gu

From: David Winsemius
Date: 2012-01-19 21:46
To: guxiaobo1982
CC: r-help; ds5j
Subject: Re: [R] What does the : operator mean in glm formulas

On Jan 19, 2012, at 8:02 AM, Xiaobo Gu wrote:


Hi,

I see the following is the credit scoreing in R guide :

m2-glm(formula = good_bad ~ checking + duration + history+ purpose
+amount + savings + employed + installp + marital +
coapp +age + other + depends + telephon + foreign +checking:amount

What does checking:amount mean?


?formula

--

David Winsemius, MD
West Hartford, CT


David Winsemius, MD
West Hartford, CT

__
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] Filling color's points in legend's plot in R

2012-01-19 Thread Tsidkenu
Thanks for the reply but I want to color (of gray) the triangle, square,
circle and the other symbol appear in the legend.


--
View this message in context: 
http://r.789695.n4.nabble.com/Filling-color-s-points-in-legend-s-plot-in-R-tp4308966p4310070.html
Sent from the R help mailing list archive at Nabble.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] r help: source-function is very slow

2012-01-19 Thread Uwe Ligges



On 19.01.2012 14:25, Jos van Nijnatten wrote:

Hello everybody,
I noticed a performance problem when using the source-function in R.
When I try to source an r script that is located in the same directory
as the script I execute via command line ('R -f file.r' contents
'source(someOtherScript.r)') it's very fast. But if I put
'someOtherScript.r' in another directory (say ../../R) R takes moments,
if not minutes to locate and load the script. Is there another way to do
this that is not slow?


We are certainly interested in a reproducible example. Or could it be 
that your ../../R is on some other possibly network mounted file system?


Uwe Ligges





Thanks, Jos



__
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] Filling color's points in legend's plot in R

2012-01-19 Thread Uwe Ligges



On 19.01.2012 15:02, Tsidkenu wrote:

Thanks for the reply but I want to color (of gray) the triangle, square,
circle and the other symbol appear in the legend.


PLEASE do read the posting guide.

Uwe Ligges





--
View this message in context: 
http://r.789695.n4.nabble.com/Filling-color-s-points-in-legend-s-plot-in-R-tp4308966p4310070.html
Sent from the R help mailing list archive at Nabble.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.


__
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 help: source-function is very slow

2012-01-19 Thread Duncan Murdoch

On 12-01-19 8:25 AM, Jos van Nijnatten wrote:

Hello everybody,
I noticed a performance problem when using the source-function in R.
When I try to source an r script that is located in the same directory
as the script I execute via command line ('R -f file.r' contents
'source(someOtherScript.r)') it's very fast. But if I put
'someOtherScript.r' in another directory (say ../../R) R takes moments,
if not minutes to locate and load the script. Is there another way to do
this that is not slow?


R uses the same method in both instances.  If there's a difference in 
timing, it's almost certainly because there's something going on with 
your OS or file system.


Duncan Murdoch

__
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 with .csv file reading !

2012-01-19 Thread aaurouss
 Hello,

Here's my problem :

I have a csv file which I have to read with read.table() function (or
read.csv). The file has about 6 lines whose data are written this way: 
character;character;character;character

14/10/2010 13:10;0;49;0;49;

14/10/2010 13:20;0;49;0;49;

14/10/2010 13:30;0;49;0;49;


I tried to use the function this way:read.csv(file.csv,sep =
;,colClasses = character, fill=TRUE,as.is=TRUE,h=FALSE).

Here's what I get as an error:
Error in fill  length(col.names)  cols :
  type 'x' incorrect in 'x  y'

I can't find any set of options with any of the read functions that work.

Any ideas ?

Thanks


--
View this message in context: 
http://r.789695.n4.nabble.com/Help-with-csv-file-reading-tp4310138p4310138.html
Sent from the R help mailing list archive at Nabble.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] cacheSweave questions (usage and forward compatibility)

2012-01-19 Thread Yihui Xie
Tal,

You probably need to cc the package author for reliable answers, but
my attempts are below anyway:

1) true or TRUE? I'm not exactly sure how this option is parsed
(checking the source code is one way to go), but for knitr, it does
not allow true to mean TRUE, and \SweaveOpts{cache=TRUE} should work
as expected; if cacheSweave follows the convention of Sweave strictly,
\SweaveOpts{cache=true} should have worked (true means TRUE);

2) In the past I mainly used cacheSweave via pgfSweave, and I'm more
familiar with the latter; one thing I'm sure is that it does not
delete old cache files, so if you add 1 and remove 1, it will probably
revert to the old cache and skip the evaluation, and two sets of cache
files will be there; knitr removes old cache each time the new cache
is built, so in your case, the chunk will be re-evaluated after 1 is
removed;

3) This is one of the big motivations of knitr (see the section
Motivation in http://yihui.github.com/knitr/); again, I cannot say
much about cacheSweave since I did not go through its source code as
frequently as pgfSweave's, but I know at least the latter is facing
inconsistencies with official Sweave (e.g. issues #36/#34/#25/... in
its GitHub repository);

Regards,
Yihui
--
Yihui Xie xieyi...@gmail.com
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Thu, Jan 19, 2012 at 4:56 AM, Tal Galili tal.gal...@gmail.com wrote:
 Hello all,

 I would like to ask several questions regarding cacheSweave:
 1) Is there a way to set cache=true globally? (I tried it
 using \SweaveOpts but it didn't seem to work)
  2) Is there a way to flush specific cache once it is created? (other
 then erasing the entire cache directory)?  Changing the code in the code
 chunk seems to do it, but I am not sure to what extent.  For example - if I
 add at the end of the code chunk a number (say 1 - that will be printed),
 it will reevaluate the code chunk.  However, if I remove that number, it
 will not re-evaluate the code chunk.
 3) To what extent does cacheSweave rely on Sweave? For example: I see that
 the latest Sweave document is from October 31, 2011 while the latest update
 to cacheSweave is from 2011-07-23.  Does that mean that there are new
 features or bug fixes that are introduced to Sweave which are not available
 through cacheSweave?  (from the manual it says that cacheSweave is based on
 the code version of R 2.5.0.  What does that mean in terms of
 features/bugs?)

 Thank you for your help,
 Tal







 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com (English)
 --

        [[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-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 help: source-function is very slow

2012-01-19 Thread Jos van Nijnatten

Hello Uwe, Duncan and the rest of the community,
It indeed seemed to be a file system problem and I'm lucky to figure 
that out before it crashed. New computer's great and everything is 
working fine again.

Sorry for wasting your time ;-)


On Thursday, January 19, 2012 15:16, Duncan Murdoch wrote:

On 12-01-19 8:25 AM, Jos van Nijnatten wrote:

Hello everybody,
I noticed a performance problem when using the source-function in R.
When I try to source an r script that is located in the same directory
as the script I execute via command line ('R -f file.r' contents
'source(someOtherScript.r)') it's very fast. But if I put
'someOtherScript.r' in another directory (say ../../R) R takes moments,
if not minutes to locate and load the script. Is there another way to do
this that is not slow?


R uses the same method in both instances. If there's a difference in 
timing, it's almost certainly because there's something going on with 
your OS or file system.


Duncan Murdoch




--
Jos van Nijnatten, BSc Candidate
Erasmus MC, Rotterdam, NL
Department of Bioinformatics
(ph) +31 1 07 04 45 51
(mob) +31 6 14 92 14 01
(e) j.vannijnat...@erasmusmc.nl

__
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] Help with .csv file reading !

2012-01-19 Thread David Winsemius


On Jan 19, 2012, at 9:22 AM, aaurouss wrote:


Hello,

Here's my problem :

I have a csv file which I have to read with read.table() function (or
read.csv). The file has about 6 lines whose data are written  
this way:

character;character;character;character

14/10/2010 13:10;0;49;0;49;

14/10/2010 13:20;0;49;0;49;

14/10/2010 13:30;0;49;0;49;


I tried to use the function this way:read.csv(file.csv,sep =
;,colClasses = character, fill=TRUE,as.is=TRUE,h=FALSE).


If you are expecting 5 columns as this would suggest then your  
colClasses argument needs to be rep(character, 5)




Here's what I get as an error:
Error in fill  length(col.names)  cols :
 type 'x' incorrect in 'x  y'

I can't find any set of options with any of the read functions that  
work.


You need to read the read.table documentation again, ... and  
again, ...  and again.


--

David Winsemius, MD
West Hartford, CT

__
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] breakpoints and nonlinear regression

2012-01-19 Thread Vito Muggeo (UniPa)

dear Julian,


Il 18/01/2012 14.36, crimsonengineer87 ha scritto:

Thanks for the comments. Yes, I also had segmented and then I went away from
that. I can't remember. I've tried using it but I get some sort of strange
error. Here's some code ...


it is difficult for me to help you without knowing which error you 
obtain.. If you refer to maximum number of iterations, it is a warning 
(not error). See the discussion in the paper on Rnews (that Achim 
suggested). The following code is expected to work


pavlu.glm- lm(Na ~ yield, data=pavludata)
pavlu.seg- segmented(pavlu.glm, seg.Z=~yield, psi=1000)
with(pavludata, plot(yield, Na))
plot(pavlu.seg, add=TRUE)

See in ?segmented and ?plot.segmented for additional examples and 
contact me off list if you have additional questions


best,
vito






pavlu.glm- glm(Na ~ yield, data=pavludata, family=gaussian)
pavlu.seg- segmented(pavlu.glm, seg.Z=~yield, psi=1000,
control=seg.control(display=FALSE))

plot.series- function()
{
plot(pavlu.seg)
plot(pavlu.seg, add=TRUE, linkinv=TRUE, lwd=2, col=2:3, lty=c(1,3))
lines(pavlu.seg, col=2, pch=19, bottom=FALSE, lwd=2)
}

jpeg(pavlu-cuttingsystem-segmented.jpg, width = 1000, height = 700, units
= px)
plot.series()

## Turn off device driver (to flush output to JPG)
dev.off()

1. I don't think I'm doing my plotting right. I'm just not sure how that
works with segmented.
2. My error is something about an error in do.call(lines) and that the
maximum number of iterations has been reached. Am I missing something with
glm or lm?

Thanks again.

--
View this message in context: 
http://r.789695.n4.nabble.com/breakpoints-and-nonlinear-regression-tp4303629p4306657.html
Sent from the R help mailing list archive at Nabble.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.



--

Vito M.R. Muggeo
Dip.to Sc Statist e Matem `Vianelli'
Università di Palermo
viale delle Scienze, edificio 13
90128 Palermo - ITALY
tel: 091 23895240
fax: 091 485726
http://dssm.unipa.it/vmuggeo

__
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] Help with .csv file reading !

2012-01-19 Thread David Winsemius


On Jan 19, 2012, at 9:34 AM, David Winsemius wrote:



On Jan 19, 2012, at 9:22 AM, aaurouss wrote:


Hello,

Here's my problem :

I have a csv file which I have to read with read.table() function (or
read.csv). The file has about 6 lines whose data are written  
this way:

character;character;character;character

14/10/2010 13:10;0;49;0;49;

14/10/2010 13:20;0;49;0;49;

14/10/2010 13:30;0;49;0;49;


I tried to use the function this way:read.csv(file.csv,sep =
;,colClasses = character, fill=TRUE,as.is=TRUE,h=FALSE).


If you are expecting 5 columns as this would suggest then your  
colClasses argument needs to be rep(character, 5)


Actually that is not correct, ... to my surprise. I didn't realize  
that colClasses would get automagically repeated.


And the other error would be thinking that TRUE is the same as TRUE.  
In this case it would appear that not all truths are self-evident.


I try to avoid partial spellings of arguments. I predict that  
continuing to use h=FALSE will get you into trouble in the long run.






Here's what I get as an error:
Error in fill  length(col.names)  cols :
type 'x' incorrect in 'x  y'

I can't find any set of options with any of the read functions that  
work.


You need to read the read.table documentation again, ... and  
again, ...  and again.


--

David Winsemius, MD
West Hartford, CT

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


David Winsemius, MD
West Hartford, CT

__
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] Split values in vector

2012-01-19 Thread Johannes Radinger
Hi,

just for explaining it a little bit furhter
here a small sample dataframe (similar to that
I am working with).


var1 -seq(1,5)
var2 -c(A,B,C,D,E)
var3 -c(00,01-1;02-3;04-1,01-2;02-1,01-0;04-12,NA)

x - data.frame(var1,var2,var3)

The final dataframe should look like:
When there is the category 00 then the column 00 should
be 1 and all others 0. The other values should be according
to the input and when the category is not stated then the value
is 0. Sounds probably a little bit confusing but hopefully
the example makes it easier to understand.

var1  var2  var3_00   var3_01   var3_02   var3_04
1 A 1 0 0 0
2 B 0 1 3 1
3 C 0 2 1 0
4 D 0 0 0 12
5 E NANANANA


When I try it with the recommended approach I get an error
when I want it executes table() and I am not sure if I will
get exactly the result I want.

X - unlist(strsplit(as.character(x$var3), split = ;, fixed = TRUE))
X - strsplit( X, split = -, fixed = TRUE)

X - sapply( X, function( x)
if( length(x) == 2)
rep( x[1], as.numeric( x[2])) else x[1]
)

table(X, useNA = always)

Thank you for you help, I really don't know how this can be handled

best regards,
johannes


 Original-Nachricht 
 Datum: Thu, 19 Jan 2012 13:42:24 +0100 (MET)
 Von: Gerrit Eichner gerrit.eich...@math.uni-giessen.de
 An: Johannes Radinger jradin...@gmx.at
 CC: R-help@r-project.org
 Betreff: Re: [R] Split values in vector

 Hi, Johannes,
 
 maybe
 
 X - unlist( strsplit( as.character( x$ART), split = ;, fixed = TRUE))
 X - strsplit( X, split = -, fixed = TRUE)
 
 X - sapply( X, function( x)
   if( length(x) == 2)
rep( x[1], as.numeric( x[2])) else x[1]
  )
 
 table(X, useNA = always)
 
 
 comes close to what you want.
 
   Hth  --  Gerrit
 
 
 On Thu, 19 Jan 2012, Johannes Radinger wrote:
 
  Hello,
 
  I have a vector which looks like
 
  x$ART
  ...
 
  [35415] 0001-1;02-1;05-1;
  [35417] 01-1; 01-1;02-1;
  [35419] 01-1; 00
  [35421] 01-1;04-1;05-1;
  [35423] 02-1; 01-1;02-1;
  [35425] 01-1;02-1;NA
  [35427] 01-1; NA
  ...
 
 
  This is a vector I got in this format. To explain it:
  there are several categories (00,01,02 etc) and its counts (values after
 -)
  So I have to split each value and create new dataframe-columns/vectors
  for each categories one column and the value should be then in the
  corresponding cell. I know that this vector has 7 categories (00-06)
  and NA values but each case (row) has not all the categories (as you can
 see).  How can do such as split?
 
  In the end I should get:
  x$ART_00, x$ART_01, x$ART_03,... with its values. In the case of NA
 all the categories should have also NA.
 
  Maybe someone can help.
 
  Thank you,
 
  Best regards
 
  Johannes
 
 
 
  -- 
  Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...
 
  __
  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.

-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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] Alaska and Hawaii map data?

2012-01-19 Thread Kevin Burton
I can plot each county of the contiguous 48 states or all of them using
variations of

 

map('county', region=c('wisconsin' . . . .)

 

in the maps package. I was wondering whether similar data was available for
Alaska and Hawaii? I was also wondering if there was a database that listed
FIPS codes for the counties in Alaska and Hawaii. Similar to 'county.fips'. 

 

Thank you.

 

Kevin Burton


[[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] Legend problem in line charts

2012-01-19 Thread Petr PIKAL
Hi
 
 Hi all,
 
 Small problem in generating the line charts.
 
 Question: Legend for the first graph is coming wrong.,  for second graph 

 correctly.  Please fix the legend postion at the down of graph.
 Plesae give me the solution.
 
 Thank you
 Devarayalu
 
 
 
 Orange1 - structure(list(REFID = c(7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
 8, 8, 8, 8, 9, 9, 9, 9), ARM = c(1, 1, 1, 1, 2, 2, 2, 2, 1, 1,
 1, 1, 2, 2, 2, 2, 1, 1, 2, 2), SUBARM = c(0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ACTTRT = structure(c(3L,
 3L, 3L, 3L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L,
 1L, 2L, 2L), .Label = c(ABC, DEF, LCD, Vehicle), class = 
factor),
 TIME1 = c(0, 2, 6, 12, 0, 2, 6, 12, 0, 2, 6, 12, 0, 2, 6,
 12, 0, 12, 0, 12), ENDPOINT = structure(c(1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L), .Label = PGA, class = factor), BASCHGA = c(0, -39,
 -47, -31, 0, -34, -25, -12, 0, -45, -47, -20, 0, -25, -30,
 -35, 0, -30, 0, -40), STATANAL = structure(c(1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L), .Label = UNK, class = factor), Art_Name = 
structure(c(1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
 2L, 2L, 2L, 2L), .Label = c(Bela_2010_206878, 
Dansinger_2010_20687812
 ), class = factor)), .Names = c(REFID, ARM, SUBARM,
 ACTTRT, TIME1, ENDPOINT, BASCHGA, STATANAL, Art_Name
 ), row.names = c(NA, 20L), class = data.frame)
 

Good that you provided data and code.

However there are some unnecessary items in your code.
AFAIU you want to plot three graphs from your data, one for each REFID 
with distinct lines for each ACTTRT. If you do not want to use lattice or 
ggplot you does not need printing your graphs inside a cycle. 

Also be aware that all levels of a factor are preserved in a subset unless 
you specifically strip the unused levels. Therefore there is a mismatch in 
legend colours and line colours.

And you can also use multipage PDF which is quite convenient.

So I would recommend slight modifications to your code.

#open one pdf
pdf (pga.pdf)

# set colours outside of cycle
nlev - max(as.numeric(Orange1$ACTTRT))
colors - rainbow(nlev)
linetype - 1:nlev
plotchar - seq(18,18+nlev,1)

#plot three graphs for each refid
for (i in 1:length(refid)) {
refid1 - subset(Orange1, REFID == refid[i])
xrange - range(refid1$TIME1)
yrange - range(refid1$BASCHGA)
plot(xrange, yrange, type=n, xlab=TIME1 (WK), ylab=BASCHGA (mm) )


# change ACTTRT to numeric
actnum - as.numeric(refid1$ACTTRT)
# add lines and select only appropriate colours for each line
for (j in unique(actnum)) {
ACTTRT - subset(refid1, actnum==j)
lines(ACTTRT$TIME1, ACTTRT$BASCHGA, type=b, lwd=1.5,lty=linetype[j], 
col=colors[j], pch=plotchar[j])
paste(REFID = , unique(refid1$REFID), ; STATANAL = , 
unique(refid1$STATANAL), sep=) - x
title(x)
}

#add legend and again select appropriate colours
legend(xrange[1], yrange[2], unique(refid1$ACTTRT), cex=0.8, 
col=colors[unique(actnum)],
  pch=plotchar[unique(actnum)], lty=linetype[unique(actnum)])
#bottomright, bottom, bottomleft, left, topleft, top, 
topright, right and center
}
dev.off()

And one comment. Colors is a function in base R (grDevices) so it is 
recommendable to use different name for colours vector.
See ?colors

Regards
Petr


 
 unique(Orange1$REFID) - refid
 # Create Line Chart
 for (i in 1:length(refid)) {
 # convert factor to numeric for convenience
 refid1 - subset(Orange1, REFID == refid[i])
 refid1$ACTTRTnum - as.numeric(refid1$ACTTRT)
 nACTTRTs - max(refid1$ACTTRTnum)
 
 # get the range for the x and y axis
 xrange - range(refid1$TIME1)
 yrange - range(refid1$BASCHGA)
 
 # set up the plot
 pdf (paste(pga, i, .pdf, sep=''))
 print(plot(xrange, yrange, type=n, xlab=TIME1 (WK),
ylab=BASCHGA (mm) ))
 colors - rainbow(nACTTRTs)
 linetype - c(1:nACTTRTs)
 plotchar - seq(18,18+nACTTRTs,1)
 
 # add lines
 
 for (i in 1:nACTTRTs) {
   ACTTRT - subset(refid1, ACTTRTnum==i)
   print(lines(ACTTRT$TIME1, ACTTRT$BASCHGA, type=b, lwd=1.5,
 lty=linetype[i], col=colors[i], pch=plotchar[i]))
 }
 
 # add a title and subtitle
 paste(REFID = , unique(refid1$REFID), ; STATANAL = , unique(refid1
 $STATANAL), sep=) - x
 title(x)
 
 
 # add a legend
 legend(xrange[1], yrange[2], unique(refid1$ACTTRT), cex=0.8, col=colors,
pch=plotchar, lty=linetype)
 #bottomright, bottom, bottomleft, left, topleft, top, 
 topright, right and center
 dev.off()
 }
 
 
[[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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 

Re: [R] graph paper look

2012-01-19 Thread David L Carlson
You could look at grid(), but the Note in the documentation suggests If
more fine tuning is required, use abline(h = ., v = .) directly. Also
grid() uses the default axis positions so if you specify details of the axis
with xlim, ylim, etc the grid does not line up on the tickmarks. 

Using abline is pretty simple. Use xpd=TRUE to get abline to draw outside
the plot region.

oldpar - par(xpd=TRUE)
plot(c(0,1),c(0,1), axes=FALSE, pch=NA, xlab=, ylab=) 
abline(v=seq(-1, 2, .1), h=seq(-1, 2, .1), lty=3, col=gray)
abline(v=seq(-1, 2, .5), h=seq(-1, 2, .5), lty=1, col=gray)
par(oldpar)

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Erin Hodgess
Sent: Wednesday, January 18, 2012 7:19 PM
To: r-help@r-project.org
Subject: [R] graph paper look

Dear R People:

Short of doing a series of ablines, is there a way to produce graph
paper in R please?

Thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@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.

__
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] Reading in tab (and space) delimited data within a script XXXX

2012-01-19 Thread Dan Abner
Hello everyone,

I use Bob Muenchen's approach for reading in in-stream (to use SAS
parlance) delimited data within a script. This works great:


mystring -
id,workshop,gender,q1,q2,q3,q4
 1,1,f,1,1,5,1
 2,2,f,2,1,4,1
 3,1,f,2,2,4,3
 4,2, ,3,1, ,3
 5,1,m,4,5,2,4
 6,2,m,5,4,5,5
 7,1,m,5,3,4,4
 8,2,m,4,5,5,5

mydata - read.table( textConnection(mystring),
   header=TRUE, sep=,,
   row.names=id, na.strings= )
closeAllConnections()
mydata

Can anyone suggest a similar approach for reading in tab-delimited or
single space delimited data? Example data:

data3-
OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL AGEGROUP
21 76 M 84 5 3.2 0.9 3
22 76 M  5 2.18 0.84 3
23 68 M 82 5 2.15 0.52 1
24 69 M 84 5 2.3 1.36 1
25 76 F 100 3 25.3 1.07 3
26 70 F 90 3 20 0.97 2
27 71 F 109 3 22.3 0.94 2
28 70 -99 65 3 24.3 1.42 2
29 74 F 61 3 25 0.87 2
30 74 F 62 3 23.3 0.94 2

Thanks!

Dan

[[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] cannot dyn.load dll from path

2012-01-19 Thread Adrian Dragulescu


Hello,

I'm on Windows, and according to the documentation R searches along the 
search path when looking for dll's for dyn.load.


For illustration, I've copied the XML.dll from package XML in the C:/Temp 
folder


  if (file.exists(C:/Temp/XML.dll)) {
Sys.setenv(path = paste(C:/Temp;, Sys.getenv(path), sep=))
dyn.load(XML.dll)   # doesn't find it!
  }


  head(strsplit(Sys.getenv(path), ;)[[1]])  # C:/Temp is there

  dyn.load(C:/Temp/XML.dll)  # works fine

Am I misreading the documentation?

Thank you,
Adrian


sessionInfo()

R version 2.14.1 (2011-12-22)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United 
States.1252

[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base




__
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] Reading in tab (and space) delimited data within a script XXXX

2012-01-19 Thread R. Michael Weylandt
Simply change the sep  = , argument of read table:   for a space
and \t for a tab. E.g., read.table(text = data3, sep =  , header =
TRUE)

Take a look at ?read.table for more info about the sep argument (In
particular the special behavior of the default sep = )

Thanks for the well-posed question and working data.

Michael

On Thu, Jan 19, 2012 at 11:37 AM, Dan Abner dan.abne...@gmail.com wrote:
 Hello everyone,

 I use Bob Muenchen's approach for reading in in-stream (to use SAS
 parlance) delimited data within a script. This works great:


 mystring -
 id,workshop,gender,q1,q2,q3,q4
  1,1,f,1,1,5,1
  2,2,f,2,1,4,1
  3,1,f,2,2,4,3
  4,2, ,3,1, ,3
  5,1,m,4,5,2,4
  6,2,m,5,4,5,5
  7,1,m,5,3,4,4
  8,2,m,4,5,5,5

 mydata - read.table( textConnection(mystring),
   header=TRUE, sep=,,
   row.names=id, na.strings= )
 closeAllConnections()
 mydata

 Can anyone suggest a similar approach for reading in tab-delimited or
 single space delimited data? Example data:

 data3-
 OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL AGEGROUP
 21 76 M 84 5 3.2 0.9 3
 22 76 M  5 2.18 0.84 3
 23 68 M 82 5 2.15 0.52 1
 24 69 M 84 5 2.3 1.36 1
 25 76 F 100 3 25.3 1.07 3
 26 70 F 90 3 20 0.97 2
 27 71 F 109 3 22.3 0.94 2
 28 70 -99 65 3 24.3 1.42 2
 29 74 F 61 3 25 0.87 2
 30 74 F 62 3 23.3 0.94 2

 Thanks!

 Dan

        [[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-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] Reading in tab (and space) delimited data within a script XXXX

2012-01-19 Thread Dan Abner
Hi Michael,

Thanks for your responses.

When I do this, I am not successful. What am I doing wrong?

 data3-
+ OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP
+ 2176M8453.20.93
+ 2276M52.180.843
+ 2368M8252.150.521
+ 2469M8452.31.361
+ 2576F100325.31.073
+ 2670F903200.972
+ 2771F109322.30.942
+ 2870-9965324.31.422
+ 2974F613250.872
+ 3074F62323.30.942


 data3-read.table(textConnection(data3),
+header=TRUE,sep= ,
+row.names=OBSNO)
Error in data[[rowvar]] : attempt to select less than one element
 closeAllConnections()
 data3
[1]
OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP\n2176M8453.20.93\n2276M52.180.843\n2368M8252.150.521\n2469M8452.31.361\n2576F100325.31.073\n2670F903200.972\n2771F109322.30.942\n2870-9965324.31.422\n2974F613250.872\n3074F62323.30.942


 data3-read.table(textConnection(data3),
+header=TRUE,sep=\t,
+row.names=OBSNO)
Error in data[[rowvar]] : attempt to select less than one element
 closeAllConnections()
 data3
[1]
OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP\n2176M8453.20.93\n2276M52.180.843\n2368M8252.150.521\n2469M8452.31.361\n2576F100325.31.073\n2670F903200.972\n2771F109322.30.942\n2870-9965324.31.422\n2974F613250.872\n3074F62323.30.942





On Thu, Jan 19, 2012 at 11:45 AM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:

 Simply change the sep  = , argument of read table:   for a space
 and \t for a tab. E.g., read.table(text = data3, sep =  , header =
 TRUE)

 Take a look at ?read.table for more info about the sep argument (In
 particular the special behavior of the default sep = )

 Thanks for the well-posed question and working data.

 Michael

 On Thu, Jan 19, 2012 at 11:37 AM, Dan Abner dan.abne...@gmail.com wrote:
  Hello everyone,
 
  I use Bob Muenchen's approach for reading in in-stream (to use SAS
  parlance) delimited data within a script. This works great:
 
 
  mystring -
  id,workshop,gender,q1,q2,q3,q4
   1,1,f,1,1,5,1
   2,2,f,2,1,4,1
   3,1,f,2,2,4,3
   4,2, ,3,1, ,3
   5,1,m,4,5,2,4
   6,2,m,5,4,5,5
   7,1,m,5,3,4,4
   8,2,m,4,5,5,5
 
  mydata - read.table( textConnection(mystring),
header=TRUE, sep=,,
row.names=id, na.strings= )
  closeAllConnections()
  mydata
 
  Can anyone suggest a similar approach for reading in tab-delimited or
  single space delimited data? Example data:
 
  data3-
  OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL AGEGROUP
  21 76 M 84 5 3.2 0.9 3
  22 76 M  5 2.18 0.84 3
  23 68 M 82 5 2.15 0.52 1
  24 69 M 84 5 2.3 1.36 1
  25 76 F 100 3 25.3 1.07 3
  26 70 F 90 3 20 0.97 2
  27 71 F 109 3 22.3 0.94 2
  28 70 -99 65 3 24.3 1.42 2
  29 74 F 61 3 25 0.87 2
  30 74 F 62 3 23.3 0.94 2
 
  Thanks!
 
  Dan
 
 [[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.htmlhttp://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] Reading in tab (and space) delimited data within a script XXXX

2012-01-19 Thread David Winsemius


On Jan 19, 2012, at 11:37 AM, Dan Abner wrote:


Hello everyone,

I use Bob Muenchen's approach for reading in in-stream (to use SAS
parlance) delimited data within a script. This works great:


mystring -
id,workshop,gender,q1,q2,q3,q4
1,1,f,1,1,5,1
2,2,f,2,1,4,1
3,1,f,2,2,4,3
4,2, ,3,1, ,3
5,1,m,4,5,2,4
6,2,m,5,4,5,5
7,1,m,5,3,4,4
8,2,m,4,5,5,5

mydata - read.table( textConnection(mystring),
  header=TRUE, sep=,,
  row.names=id, na.strings= )
closeAllConnections()
mydata

Can anyone suggest a similar approach for reading in tab-delimited or
single space delimited data? Example data:


You need to read the help page more thoroughly. Either tab or space  
are members of the whitespace collection of delimiters which are the  
default separators in read.table(). The would be a problem with spaces  
as na.strngs but you seem to have -99 in that role below.




?read.table


data3-
OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL AGEGROUP
21 76 M 84 5 3.2 0.9 3
22 76 M  5 2.18 0.84 3
23 68 M 82 5 2.15 0.52 1
24 69 M 84 5 2.3 1.36 1
25 76 F 100 3 25.3 1.07 3
26 70 F 90 3 20 0.97 2
27 71 F 109 3 22.3 0.94 2
28 70 -99 65 3 24.3 1.42 2
29 74 F 61 3 25 0.87 2
30 74 F 62 3 23.3 0.94 2

Thanks!

Dan

[[alternative HTML version deleted]]


Still not sending plain text, Dan.

--
David Winsemius, MD
West Hartford, CT

__
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 package dev: how to export constant?

2012-01-19 Thread Jonas Stein
 Jonas, I've just seen your function 'sistring' code and it's different from
 the code in

Thanks a lot for reporting this bug. It is fixed now in the git 
repository.

I added some examples, but they do not work:

R CMD check sitools

= snip
 ### ** Examples
 
 library(sitools)
 
 # volume of a dice in metres
 a - 1 * centi
Error: object 'centi' not found
= snap

Any hints?
Do you think i should rename the convert function to 
float2si or something like that?
Perhaps someone needs a si2float converter in future...

Betatesters are welcome. After some more testing i want to upload the 
package to the R package collection.

kind regards,

-- 
Jonas Stein n...@jonasstein.de

__
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] Reading in tab (and space) delimited data within a script XXXX

2012-01-19 Thread Jeff Newmiller
Cannot see what you are doing wrong, since you don't show that. It looks like 
you have eliminated all delimiters from your input data. Perhaps your editor 
settings are doing something to your data (though usually tabs if altered 
become spaces).
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Dan Abner dan.abne...@gmail.com wrote:

Hi Michael,

Thanks for your responses.

When I do this, I am not successful. What am I doing wrong?

 data3-
+ OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP
+ 2176M8453.20.93
+ 2276M52.180.843
+ 2368M8252.150.521
+ 2469M8452.31.361
+ 2576F100325.31.073
+ 2670F903200.972
+ 2771F109322.30.942
+ 2870-9965324.31.422
+ 2974F613250.872
+ 3074F62323.30.942


 data3-read.table(textConnection(data3),
+header=TRUE,sep= ,
+row.names=OBSNO)
Error in data[[rowvar]] : attempt to select less than one element
 closeAllConnections()
 data3
[1]
OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP\n2176M8453.20.93\n2276M52.180.843\n2368M8252.150.521\n2469M8452.31.361\n2576F100325.31.073\n2670F903200.972\n2771F109322.30.942\n2870-9965324.31.422\n2974F613250.872\n3074F62323.30.942


 data3-read.table(textConnection(data3),
+header=TRUE,sep=\t,
+row.names=OBSNO)
Error in data[[rowvar]] : attempt to select less than one element
 closeAllConnections()
 data3
[1]
OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP\n2176M8453.20.93\n2276M52.180.843\n2368M8252.150.521\n2469M8452.31.361\n2576F100325.31.073\n2670F903200.972\n2771F109322.30.942\n2870-9965324.31.422\n2974F613250.872\n3074F62323.30.942





On Thu, Jan 19, 2012 at 11:45 AM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:

 Simply change the sep  = , argument of read table:   for a space
 and \t for a tab. E.g., read.table(text = data3, sep =  , header
=
 TRUE)

 Take a look at ?read.table for more info about the sep argument (In
 particular the special behavior of the default sep = )

 Thanks for the well-posed question and working data.

 Michael

 On Thu, Jan 19, 2012 at 11:37 AM, Dan Abner dan.abne...@gmail.com
wrote:
  Hello everyone,
 
  I use Bob Muenchen's approach for reading in in-stream (to use
SAS
  parlance) delimited data within a script. This works great:
 
 
  mystring -
  id,workshop,gender,q1,q2,q3,q4
   1,1,f,1,1,5,1
   2,2,f,2,1,4,1
   3,1,f,2,2,4,3
   4,2, ,3,1, ,3
   5,1,m,4,5,2,4
   6,2,m,5,4,5,5
   7,1,m,5,3,4,4
   8,2,m,4,5,5,5
 
  mydata - read.table( textConnection(mystring),
header=TRUE, sep=,,
row.names=id, na.strings= )
  closeAllConnections()
  mydata
 
  Can anyone suggest a similar approach for reading in tab-delimited
or
  single space delimited data? Example data:
 
  data3-
  OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL AGEGROUP
  21 76 M 84 5 3.2 0.9 3
  22 76 M  5 2.18 0.84 3
  23 68 M 82 5 2.15 0.52 1
  24 69 M 84 5 2.3 1.36 1
  25 76 F 100 3 25.3 1.07 3
  26 70 F 90 3 20 0.97 2
  27 71 F 109 3 22.3 0.94 2
  28 70 -99 65 3 24.3 1.42 2
  29 74 F 61 3 25 0.87 2
  30 74 F 62 3 23.3 0.94 2
 
  Thanks!
 
  Dan
 
 [[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.htmlhttp://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-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] fitting an exp model

2012-01-19 Thread arivald
Hello there, 

I am trying to fit an exponential model using nls to some data. 

#data 
t - c(0,15,30,60,90,120,240,360,480)
var - c(0.36,9.72,15.50,23.50,31.44,40.66,59.81,73.11,81.65)
df - data.frame(t, var)

# model  
# var ~ a+b*(1-exp(-k*t))

# I'm looking for values of a,b and k

#  formula 
#  mod - nls(formula = var ~ a+b *(1-exp((-k)*t)), start=list(a=0, b=10,
k=0), trace=T)

# It fails and I get the following error - 
Error in nlsModel(formula, mf, start, wts) : 
  singular gradient matrix at initial parameter estimates 

I was trying different methods and looking for some solutions but nothing is
working...

Any suggestions how I can fix this? I appreciated any help 
Thanks in advance. 


--
View this message in context: 
http://r.789695.n4.nabble.com/fitting-an-exp-model-tp4310752p4310752.html
Sent from the R help mailing list archive at Nabble.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.


[R] Global sensitivity indices using sensitivity package: sobol, sobol2002

2012-01-19 Thread Adiaba
Dear R users,
I have been trying to estimate global sensitivity indices such as the sobol
1st and 2nd order indices. I managed to obtain the PRCC.

The example presented in the sensitivity package on sobol2002 seems to work
well for linear models: for example: calculate y for given x values. 

However, when trying to apply this technique to dynamic models (SIR type),
the error messages just keep spinning from one angle to another. Even the
decoupled approach still gives errors. These may be likely due to
misunderstanding of the indices or the application of the approach to
dynamic models. Here is an example: 

rm(list=ls())#clears objects
##Triangular distribution used for generating samples
rtri - function(n=1,min=0,max=1,ml=0.5) {
  if((mlmin)||(mlmax)) {
stop(ml outside of range [min max])
  }
u - runif(n)
  mode - (ml-min)/(max-min) # mode defined in range [0 1] (rescaling will
be done last)

  s1 - which(u=mode)
  s2 - which(umode)

  u[s1] - sqrt(mode*u[s1])
  u[s2] - 1-sqrt((1-mode)*(1-u[s2]))

  min+(max-min)*u
  }



###Loading required packages
#install.packages(odesolve)
library(odesolve)
#install.packages(sensitivity,dependencies=T)
library(sensitivity)




###function that generates responses
simfunzcom-function(xnews1,So=4250, I=250, R=0, No=4500){
SIRdob1- function(t, x, parms){
with(as.list(c(parms,x)),{
dS - (xnews1[, 2]-xnews1[, 4]*N)*(S+R+I*xnews1[, 6]*(1-xnews1[,
9]))-xnews1[, 3]*S + xnews1[,7]*R-(xnews1[, 1]*I*S)/N
dI - (xnews1[, 1]*I*S)/N + I*(xnews1[, 2]-xnews1[, 3]*N)*xnews1[,
9]*xnews1[, 6]-(xnews1[, 8]+xnews1[, 3]+xnews1[, 5])*I
dR - xnews1[, 5]*I -(xnews1[, 3] + xnews1[,7])*R
dN-(xnews1[, 2]-xnews1[, 4]*N)*N-xnews1[, 8]*I-(xnews1[, 2]-xnews1[,
4]*N)*(1-xnews1[, 6])*I
der - c(dS, dI,dR,dN)
list(der)  # the output must be returned
}) # end of 'with'
}  # end of function definition
yout-matrix(0,100,100)
parms1-xnews1
dt- seq(1,50,1)
inits1 - c(S=xnews1[, 10], I=xnews1[, 11], R=xnews1[, 12],N=xnews1[, 13])
for(j in 1:100){
simulation2 - as.data.frame(lsoda(inits=inits1, times=dt, funct=SIRdob1,
parms=parms1[j, ]))
attach(simulation2)
 yout[j]-as.numeric(simulation2[50 , 3])
}
yout
}


Input data 1
n-10
lambda-rtri(n,min=4,max=7,ml=5.8)
a-rtri(n,min=0.51,max=0.87,ml=0.64)
b-rtri(n,min=0.0001,max=0.01,ml=0.001)
phi-rtri(n,min=0.06,max=0.05,ml=0.4)
v-rtri(n,min=0.3,max=0.8,ml=0.5)
rho -rtri(n,min=0.1,max=0.9,ml=0.5)
delta -rtri(n,min=0.01,max=0.65,ml=0.2)
alpha-rtri(n,min=0.0001,max=0.1,ml=0.005)
e-rtri(n,min=0.4,max=1.3,ml=0.9)
xnews11-data.frame(lambda, a, b, phi, v, rho, delta, alpha,
e,So=4250,Io=250,Ro=0,No=4500)




###input data 2
n-10
lambda - rtri(n,min=4,max=7,ml=5.8)
a- rtri(n,min=0.51,max=0.87,ml=0.64)
b - rtri(n,min=0.0001,max=0.01,ml=0.001)
phi - rtri(n,min=0.06,max=0.05,ml=0.4)
v- rtri(n,min=0.3,max=0.8,ml=0.5)
rho - rtri(n,min=0.1,max=0.9,ml=0.5)
delta - rtri(n,min=0.01,max=0.65,ml=0.2)
alpha- rtri(n,min=0.0001,max=0.1,ml=0.005)
e- rtri(n,min=0.4,max=1.3,ml=0.9)
xnews2-data.frame(lambda, a,b, phi, v, rho, delta, alpha,
e,So=4250,Io=250,Ro=0,No=4500)

###sibol2002
finsibcom - sobol2002(model = simfunzcom, X1 = xnews1, X2 = xnews2, nboot =
100)



decoupled approach
sa - sobol(model = simfunzcom, X1 = xnews11, X2 = xnews2,nboot = 100)
xnews3-data.frame(lambda=sa$X$lambda, a=sa$X$a,b=sa$X$b, phi=sa$X$phi,
v=sa$X$v, rho=sa$X$rho, delta=sa$X$delta, alpha=sa$X$alpha, e=sa$X$e)
resp-simfunzcom(xnews2)
tell(sa,resp)



Please kindly direct this analysis or suggest articles that have
successfully applied this technique. The emails of the authors of
sensitivity package don't seem to work. All emails came back..

All assistance and directions is appreciated.




--
View this message in context: 
http://r.789695.n4.nabble.com/Global-sensitivity-indices-using-sensitivity-package-sobol-sobol2002-tp4310570p4310570.html
Sent from the R help mailing list archive at Nabble.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.


[R] R connect to Informix Database

2012-01-19 Thread Scotty33
Hi,

I am new to R and wondering if it is possible for it to connect to an
Informix database. I tried google but nothing came back that I could figure
out. 

Can somebody tell me if its possible (which I believe it is) and how to
connect to an Informix database using R.

Thanks!

--
View this message in context: 
http://r.789695.n4.nabble.com/R-connect-to-Informix-Database-tp4310594p4310594.html
Sent from the R help mailing list archive at Nabble.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.


[R] RODBC problem inserting into tables

2012-01-19 Thread Faensen
I have a problem with RODBC statements that seems to be related to inserting
data into a table during an SQL batch (MS SQL Server). It started from a
stored procedure that didn't return data to R but I could boil it down to
the following simplified code snippets.

The first one does work:
sqlQuery(channel, 
CREATE TABLE tab (x int)

SELECT 'Test' AS Name

INSERT INTO tab(x)
VALUES(0)

DROP TABLE tab
)

But running the SELECT statement after the INSERT statement does not:
sqlQuery(channel, 
CREATE TABLE tab (x int)

INSERT INTO tab(x)
VALUES(0)

SELECT 'Test' AS Name

DROP TABLE tab
)

The table is not even used in the SELECT statement (of course, in my real
code it is).

I would appreciate any help

Daniel



--
View this message in context: 
http://r.789695.n4.nabble.com/RODBC-problem-inserting-into-tables-tp4310772p4310772.html
Sent from the R help mailing list archive at Nabble.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] R connect to Informix Database

2012-01-19 Thread R. Michael Weylandt michael.weyla...@gmail.com
If you can't get an answer here it may be worth posting to the R-SIG-DB list in 
24 hours or so. (special interest group for databases)

Data bases are not an area I know at all, but I think RODBC attempts to work 
with a universal database standard so that might be worth exploring. But like I 
said: just spitballing. 

Best of luck,
Michael Weylandt



On Jan 19, 2012, at 11:51 AM, Scotty33 scott.randall...@gmail.com wrote:

 Hi,
 
 I am new to R and wondering if it is possible for it to connect to an
 Informix database. I tried google but nothing came back that I could figure
 out. 
 
 Can somebody tell me if its possible (which I believe it is) and how to
 connect to an Informix database using R.
 
 Thanks!
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/R-connect-to-Informix-Database-tp4310594p4310594.html
 Sent from the R help mailing list archive at Nabble.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.

__
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] cannot dyn.load dll from path

2012-01-19 Thread Duncan Murdoch

On 19/01/2012 11:19 AM, Adrian Dragulescu wrote:

Hello,

I'm on Windows, and according to the documentation R searches along the
search path when looking for dll's for dyn.load.

For illustration, I've copied the XML.dll from package XML in the C:/Temp
folder

if (file.exists(C:/Temp/XML.dll)) {
  Sys.setenv(path = paste(C:/Temp;, Sys.getenv(path), sep=))
  dyn.load(XML.dll)   # doesn't find it!
}


head(strsplit(Sys.getenv(path), ;)[[1]])  # C:/Temp is there

dyn.load(C:/Temp/XML.dll)  # works fine

Am I misreading the documentation?


I believe that search is done by Windows, and different versions are 
very inconsistent about search order.  However, one thing I would guess 
is that recent versions would require backslashes rather than forward 
slashes in PATH.  When R gets a path, it generally translates the 
slashes, but if you're relying on Windows to do it, you're stuck with 
what they decide to do.


Duncan Murdoch

__
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] state multi-state modeling using hidden markov routine in the msm package

2012-01-19 Thread Stephen Nyangoma
Hello Chris,

I am trying to fit a 4 state multi-state model using hidden markov routine in 
the msm package.

1. initial parameters:



twoway4.q - rbind(c(0, 0.25, 0, 0.25), c(0.166,
0, 0.166, 0.166), c(0, 0.25, 0, 0.25), c(0,
0, 0, 0))



ematrix - rbind(
c(0, 0.01, 0, 0),
c(0.01, 0, 0.01,0),
c(0, 0.1, 0, 0),
c(0, 0, 0, 0))

2. the model:



msm_covariates_sexandage - msm(state ~ duration, subject = SerialNo,
data = Data, qmatrix = twoway4.q, ematrix = ematrix,death = 4, obstrue = 
firstobs, covariates = ~ sex + age, method = BFGS, control = list(reltol = 
1e-10, fnscale = 5, trace=1,REPORT=1))

msm stops after only 100 iterations and fails to compute the Hessian (See the 
output below).  Why is it stopping at 100 only iterations yet i have specified 
reltol = 1e-10?

One additional information is that when i exclude age, the model converges 
without any problem. I have tried using age groups instead of actual age but no 
convergence can be achieved.
I have also tried subsetting the data in various biologically meaningful groups 
but there would be no convergence.





3. the R output:

 msm_covariates_sex - msm(state ~ duration, subject = SerialNo,
+ data = Data, qmatrix = twoway4.q, ematrix = ematrix,death = 4, obstrue = 
firstobs, covariates = ~ sex + age, method = BFGS, control = list(reltol = 
1e-10, fnscale = 5, trace=1,REPORT=1))
initial  value 0.567920
iter   2 value 0.547379
iter   3 value 0.463524
iter   4 value 0.439987
iter   5 value 0.426417
iter   6 value 0.420621
iter   7 value 0.417181
iter   8 value 0.414153
iter   9 value 0.410340
iter  10 value 0.406045
iter  11 value 0.403618
iter  12 value 0.403025
iter  13 value 0.402781
iter  14 value 0.402672
iter  15 value 0.402653
iter  16 value 0.402630
iter  17 value 0.402560
iter  18 value 0.402429
iter  19 value 0.402221
iter  20 value 0.402051
iter  21 value 0.401978
iter  22 value 0.401944
iter  23 value 0.401903
iter  24 value 0.401811
iter  25 value 0.401622
iter  26 value 0.401311
iter  27 value 0.400978
iter  28 value 0.400814
iter  29 value 0.400788
iter  30 value 0.400780
iter  31 value 0.400759
iter  32 value 0.400714
iter  33 value 0.400602
iter  34 value 0.400372
iter  35 value 0.400056
iter  36 value 0.399865
iter  37 value 0.399761
iter  38 value 0.399743
iter  39 value 0.399706
iter  40 value 0.399636
iter  41 value 0.399464
iter  42 value 0.399158
iter  43 value 0.398792
iter  44 value 0.398584
iter  45 value 0.398524
iter  46 value 0.398516
iter  47 value 0.398490
iter  48 value 0.398478
iter  49 value 0.398443
iter  50 value 0.398400
iter  51 value 0.398308
iter  52 value 0.398223
iter  53 value 0.398222
iter  54 value 0.398192
iter  55 value 0.398190
iter  56 value 0.398164
iter  57 value 0.398163
iter  58 value 0.398162
iter  59 value 0.398159
iter  60 value 0.398151
iter  61 value 0.398136
iter  62 value 0.398115
iter  63 value 0.398099
iter  64 value 0.398093
iter  65 value 0.398092
iter  66 value 0.398091
iter  67 value 0.398089
iter  68 value 0.398082
iter  69 value 0.398066
iter  70 value 0.398033
iter  71 value 0.397984
iter  72 value 0.397950
iter  73 value 0.397936
iter  74 value 0.397934
iter  75 value 0.397933
iter  76 value 0.397927
iter  77 value 0.397919
iter  78 value 0.397906
iter  79 value 0.397897
iter  80 value 0.397894
iter  81 value 0.397894
iter  82 value 0.397893
iter  83 value 0.397891
iter  84 value 0.397887
iter  85 value 0.397877
iter  86 value 0.397855
iter  87 value 0.397818
iter  88 value 0.397772
iter  89 value 0.397731
iter  90 value 0.397715
iter  91 value 0.397710
iter  92 value 0.397706
iter  93 value 0.397701
iter  94 value 0.397697
iter  95 value 0.397689
iter  96 value 0.397668
iter  97 value 0.397645
iter  98 value 0.397628
iter  99 value 0.397611
iter 100 value 0.397597
final  value 0.397597
stopped after 100 iterations
Warning message:
In msm(state ~ duration_in_years, subject = SerialNo, data = type1Data,  :
  Could not calculate asymptotic standard errors - Hessian is not positive 
definite. Optimisation has probably not converged to the maximum likelihood


The University of Dundee is a registered Scottish Charity, No: SC015096

[[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] venn.diagram how to control circle diameter

2012-01-19 Thread Mikael Johnson
Hi there,
Is there a way to control the circle diameter in venn.diagram function of
VennDiagram package?
Thanks
Mike

[[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] Executable expressions

2012-01-19 Thread R. Michael Weylandt
Fabulous example, Baptiste!

Yeah, the knock is that it's just not at all clear and too often
symptomatic of someone trying to be too clever by half when there's
usually a better way. There are times when these tricks can be really
helpful for non-standard evaluation (e.g., the curve() function --
super cool, but not at all easy to understand on a quick read) but
overall it's just not a very R idiom. You can see where it shows up
in the wild:

which(sapply(apropos(*), function(f) any(grepl(eval(parse,
deparse(get(f)), fixed = TRUE #Speaking of a lack of clarity

Michael

On Wed, Jan 18, 2012 at 10:03 PM, baptiste auguie
baptiste.aug...@googlemail.com wrote:
 One reason might be that you can easily fool the user into running
 unexpected/unreadable commands. Guess what this does:

 cmd - paste(c(letters[c(19L, 25L, 19L, 20L, 5L, 13L)], (' ,
 letters[c(19L, 21L, 4L, 15L)],  , letters[c(4L,
 5L, 19L, 20L, 18L, 15L, 25L)],  , letters[c(1L, 12L, 12L)],  ')),
 collapse=)

 ## not run
 ## eval(parse(text=cmd))

 b.

 On 19 January 2012 11:05, Wet Bell Diver wetbelldi...@gmail.com wrote:

 for my info, why is this rarely a good idea? Is that the case for this
 particular example , or is eval(paste()) generally rarely a good idea?

 --Peter

 Op 18-1-2012 22:22, R. Michael Weylandt schreef:

 eval(parse(text = a))

 But this is rarely a good ideaperhaps you could say a little more
 about your overall goal and we could direct you to a more R-ish
 solution?

 library(fortunes)
 fortune(rethink)

 Michael

 On Wed, Jan 18, 2012 at 4:18 PM, Ajay Askoolumaa2e...@yahoo.co.uk
  wrote:

 Given

 a-c(1,2,3,4,5)

 How can  I evaluate the variable a to return a (numeric) vector
 comprising of 1,2,3,4,5? 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-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.

 __
 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] cannot dyn.load dll from path

2012-01-19 Thread Adrian Dragulescu


It doesn't work even if I set it with \\.  My path has a mixture of \\ and 
/ and other entries work fine.


if (file.exists(C:/Temp/XML.dll)) {
  Sys.setenv(path = paste(C:\\Temp;C:/Temp;, Sys.getenv(path), sep=))
  dyn.load(XML.dll)   # doesn't find it!
}
Error in inDL(x, as.logical(local), as.logical(now), ...) :
  unable to load shared object '//nas-msw-20/adrian/My Documents/XML.dll':
  LoadLibrary failure:  The specified module could not be found.




My home folder is on a network drive.

Thank you,
Adrian



On Thu, 19 Jan 2012, Duncan Murdoch wrote:


On 19/01/2012 11:19 AM, Adrian Dragulescu wrote:

Hello,

I'm on Windows, and according to the documentation R searches along the
search path when looking for dll's for dyn.load.

For illustration, I've copied the XML.dll from package XML in the C:/Temp
folder

if (file.exists(C:/Temp/XML.dll)) {
  Sys.setenv(path = paste(C:/Temp;, Sys.getenv(path), sep=))
  dyn.load(XML.dll)   # doesn't find it!
}


head(strsplit(Sys.getenv(path), ;)[[1]])  # C:/Temp is there

dyn.load(C:/Temp/XML.dll)  # works fine

Am I misreading the documentation?


I believe that search is done by Windows, and different versions are very 
inconsistent about search order.  However, one thing I would guess is that 
recent versions would require backslashes rather than forward slashes in 
PATH.  When R gets a path, it generally translates the slashes, but if you're 
relying on Windows to do it, you're stuck with what they decide to do.


Duncan Murdoch



__
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] Reading in tab (and space) delimited data within a script XXXX

2012-01-19 Thread R. Michael Weylandt
I can't reproduce your problem: both of these work just fine for me.

read.table(text = data3, header = TRUE, sep =  , row.names = OBSNO)

read.table(textConnection(data3), header = TRUE, sep =  , row.names
= OBSNO, na.string = -99)

dput(data3)

OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL AGEGROUP\n21 76 M 84 5 3.2
0.9 3\n22 76 M  5 2.18 0.84 3\n23 68 M 82 5 2.15 0.52 1\n24 69 M 84 5
2.3 1.36 1\n25 76 F 100 3 25.3 1.07 3\n26 70 F 90 3 20 0.97 2\n27 71 F
109 3 22.3 0.94 2\n28 70 -99 65 3 24.3 1.42 2\n29 74 F 61 3 25 0.87
2\n30 74 F 62 3 23.3 0.94 2

Do you have the same dput() for data3 or did the plain-text-ification
of your HTML just happen to put it in a form that works for the rest
of us? If it is the same (or if you can reproduce the problem with
data3 as I put it above) there might be something more sinister at
work. So try this verbatim

read.table(text = OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL
AGEGROUP\n21 76 M 84 5 3.2 0.9 3\n22 76 M  5 2.18 0.84 3\n23 68 M 82 5
2.15 0.52 1\n24 69 M 84 5 2.3 1.36 1\n25 76 F 100 3 25.3 1.07 3\n26 70
F 90 3 20 0.97 2\n27 71 F 109 3 22.3 0.94 2\n28 70 -99 65 3 24.3 1.42
2\n29 74 F 61 3 25 0.87 2\n30 74 F 62 3 23.3 0.94 2, sep =  ,
header = TRUE, row.names = OBSNO)

Best,

Michael

On Thu, Jan 19, 2012 at 12:23 PM, Jeff Newmiller
jdnew...@dcn.davis.ca.us wrote:
 Cannot see what you are doing wrong, since you don't show that. It looks 
 like you have eliminated all delimiters from your input data. Perhaps your 
 editor settings are doing something to your data (though usually tabs if 
 altered become spaces).
 ---
 Jeff Newmiller                        The     .       .  Go Live...
 DCN:jdnew...@dcn.davis.ca.us        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
 Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
 /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
 ---
 Sent from my phone. Please excuse my brevity.

 Dan Abner dan.abne...@gmail.com wrote:

Hi Michael,

Thanks for your responses.

When I do this, I am not successful. What am I doing wrong?

 data3-
+ OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP
+ 2176M8453.20.93
+ 2276M52.180.843
+ 2368M8252.150.521
+ 2469M8452.31.361
+ 2576F100325.31.073
+ 2670F903200.972
+ 2771F109322.30.942
+ 2870-9965324.31.422
+ 2974F613250.872
+ 3074F62323.30.942


 data3-read.table(textConnection(data3),
+    header=TRUE,sep= ,
+    row.names=OBSNO)
Error in data[[rowvar]] : attempt to select less than one element
 closeAllConnections()
 data3
[1]
OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP\n2176M8453.20.93\n2276M52.180.843\n2368M8252.150.521\n2469M8452.31.361\n2576F100325.31.073\n2670F903200.972\n2771F109322.30.942\n2870-9965324.31.422\n2974F613250.872\n3074F62323.30.942


 data3-read.table(textConnection(data3),
+    header=TRUE,sep=\t,
+    row.names=OBSNO)
Error in data[[rowvar]] : attempt to select less than one element
 closeAllConnections()
 data3
[1]
OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP\n2176M8453.20.93\n2276M52.180.843\n2368M8252.150.521\n2469M8452.31.361\n2576F100325.31.073\n2670F903200.972\n2771F109322.30.942\n2870-9965324.31.422\n2974F613250.872\n3074F62323.30.942





On Thu, Jan 19, 2012 at 11:45 AM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:

 Simply change the sep  = , argument of read table:   for a space
 and \t for a tab. E.g., read.table(text = data3, sep =  , header
=
 TRUE)

 Take a look at ?read.table for more info about the sep argument (In
 particular the special behavior of the default sep = )

 Thanks for the well-posed question and working data.

 Michael

 On Thu, Jan 19, 2012 at 11:37 AM, Dan Abner dan.abne...@gmail.com
wrote:
  Hello everyone,
 
  I use Bob Muenchen's approach for reading in in-stream (to use
SAS
  parlance) delimited data within a script. This works great:
 
 
  mystring -
  id,workshop,gender,q1,q2,q3,q4
   1,1,f,1,1,5,1
   2,2,f,2,1,4,1
   3,1,f,2,2,4,3
   4,2, ,3,1, ,3
   5,1,m,4,5,2,4
   6,2,m,5,4,5,5
   7,1,m,5,3,4,4
   8,2,m,4,5,5,5
 
  mydata - read.table( textConnection(mystring),
    header=TRUE, sep=,,
    row.names=id, na.strings= )
  closeAllConnections()
  mydata
 
  Can anyone suggest a similar approach for reading in tab-delimited
or
  single space delimited data? Example data:
 
  data3-
  OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL AGEGROUP
  21 76 M 84 5 3.2 0.9 3
  22 76 M  5 2.18 0.84 3
  23 68 M 82 5 2.15 0.52 1
  24 69 M 84 5 2.3 1.36 1
  25 76 F 100 3 25.3 1.07 3
  26 70 F 90 3 20 0.97 2
  27 71 F 109 3 22.3 0.94 2
  28 70 -99 65 3 24.3 1.42 2
  29 74 F 61 3 25 0.87 2
  30 74 F 62 3 23.3 0.94 2
 
  Thanks!
 
  Dan
 
         [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  

Re: [R] cannot dyn.load dll from path

2012-01-19 Thread Duncan Murdoch

On 19/01/2012 1:42 PM, Adrian Dragulescu wrote:

It doesn't work even if I set it with \\.  My path has a mixture of \\ and
/ and other entries work fine.

if (file.exists(C:/Temp/XML.dll)) {
Sys.setenv(path = paste(C:\\Temp;C:/Temp;, Sys.getenv(path), sep=))
dyn.load(XML.dll)   # doesn't find it!
}
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object '//nas-msw-20/adrian/My Documents/XML.dll':
LoadLibrary failure:  The specified module could not be found.


My home folder is on a network drive.


I really think you should follow the advice in ?dyn.load and use a full 
path, or go to Microsoft's site and check the rules for how LoadLibrary 
searches for DLLs.


Duncan Murdoch


Thank you,
Adrian



On Thu, 19 Jan 2012, Duncan Murdoch wrote:

  On 19/01/2012 11:19 AM, Adrian Dragulescu wrote:
  Hello,

  I'm on Windows, and according to the documentation R searches along the
  search path when looking for dll's for dyn.load.

  For illustration, I've copied the XML.dll from package XML in the C:/Temp
  folder

  if (file.exists(C:/Temp/XML.dll)) {
Sys.setenv(path = paste(C:/Temp;, Sys.getenv(path), sep=))
dyn.load(XML.dll)   # doesn't find it!
  }


  head(strsplit(Sys.getenv(path), ;)[[1]])  # C:/Temp is there

  dyn.load(C:/Temp/XML.dll)  # works fine

  Am I misreading the documentation?

  I believe that search is done by Windows, and different versions are very
  inconsistent about search order.  However, one thing I would guess is that
  recent versions would require backslashes rather than forward slashes in
  PATH.  When R gets a path, it generally translates the slashes, but if you're
  relying on Windows to do it, you're stuck with what they decide to do.

  Duncan Murdoch



__
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] Reading in tab (and space) delimited data within a script XXXX

2012-01-19 Thread David L Carlson
Your first email has

data3-
OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL AGEGROUP
21 76 M 84 5 3.2 0.9 3
22 76 M  5 2.18 0.84 3
23 68 M 82 5 2.15 0.52 1
24 69 M 84 5 2.3 1.36 1
25 76 F 100 3 25.3 1.07 3
26 70 F 90 3 20 0.97 2
27 71 F 109 3 22.3 0.94 2
28 70 -99 65 3 24.3 1.42 2
29 74 F 61 3 25 0.87 2
30 74 F 62 3 23.3 0.94 2

Which produces

 data3
 data3
[1] OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL AGEGROUP\n21 76 M 84 5 3.2
0.9 3\n22 76 M  5 2.18 0.84 3\n23 68 M 82 5 2.15 0.52 1\n24 69 M 84 5 2.3
1.36 1\n25 76 F 100 3 25.3 1.07 3\n26 70 F 90 3 20 0.97 2\n27 71 F 109 3
22.3 0.94 2\n28 70 -99 65 3 24.3 1.42 2\n29 74 F 61 3 25 0.87 2\n30 74 F 62
3 23.3 0.94 2

With the spaces intact (unlike the example you posted in your second email).


Running read.table gives an error because the second line is short one
variable (no sex apparently):

 read.table(textConnection(data3), header=TRUE, row.names=OBSNO)
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,
: 
  line 2 did not have 8 elements

There might be other errors, read.table stops at the first one. Also don't
use the same variable for the text data and the Rdata (data3). It will just
get confusing.

--
David L Carlson
Associate Professor of Anthropology
Texas AM University
College Station, TX 77843-4352




-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Jeff Newmiller
Sent: Thursday, January 19, 2012 11:24 AM
To: Dan Abner; R. Michael Weylandt
Cc: r-help@r-project.org
Subject: Re: [R] Reading in tab (and space) delimited data within a script


Cannot see what you are doing wrong, since you don't show that. It looks
like you have eliminated all delimiters from your input data. Perhaps your
editor settings are doing something to your data (though usually tabs if
altered become spaces).
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Dan Abner dan.abne...@gmail.com wrote:

Hi Michael,

Thanks for your responses.

When I do this, I am not successful. What am I doing wrong?

 data3-
+ OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP
+ 2176M8453.20.93
+ 2276M52.180.843
+ 2368M8252.150.521
+ 2469M8452.31.361
+ 2576F100325.31.073
+ 2670F903200.972
+ 2771F109322.30.942
+ 2870-9965324.31.422
+ 2974F613250.872
+ 3074F62323.30.942


 data3-read.table(textConnection(data3),
+header=TRUE,sep= ,
+row.names=OBSNO)
Error in data[[rowvar]] : attempt to select less than one element
 closeAllConnections()
 data3
[1]
OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP\n2176M8453.20.93\n2276M52.180.
843\n2368M8252.150.521\n2469M8452.31.361\n2576F100325.31.073\n2670F903200.97
2\n2771F109322.30.942\n2870-9965324.31.422\n2974F613250.872\n3074F62323.30.9
42


 data3-read.table(textConnection(data3),
+header=TRUE,sep=\t,
+row.names=OBSNO)
Error in data[[rowvar]] : attempt to select less than one element
 closeAllConnections()
 data3
[1]
OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP\n2176M8453.20.93\n2276M52.180.
843\n2368M8252.150.521\n2469M8452.31.361\n2576F100325.31.073\n2670F903200.97
2\n2771F109322.30.942\n2870-9965324.31.422\n2974F613250.872\n3074F62323.30.9
42





On Thu, Jan 19, 2012 at 11:45 AM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:

 Simply change the sep  = , argument of read table:   for a space
 and \t for a tab. E.g., read.table(text = data3, sep =  , header
=
 TRUE)

 Take a look at ?read.table for more info about the sep argument (In
 particular the special behavior of the default sep = )

 Thanks for the well-posed question and working data.

 Michael

 On Thu, Jan 19, 2012 at 11:37 AM, Dan Abner dan.abne...@gmail.com
wrote:
  Hello everyone,
 
  I use Bob Muenchen's approach for reading in in-stream (to use
SAS
  parlance) delimited data within a script. This works great:
 
 
  mystring -
  id,workshop,gender,q1,q2,q3,q4
   1,1,f,1,1,5,1
   2,2,f,2,1,4,1
   3,1,f,2,2,4,3
   4,2, ,3,1, ,3
   5,1,m,4,5,2,4
   6,2,m,5,4,5,5
   7,1,m,5,3,4,4
   8,2,m,4,5,5,5
 
  mydata - read.table( textConnection(mystring),
header=TRUE, sep=,,
row.names=id, na.strings= )
  closeAllConnections()
  mydata
 
  Can anyone suggest a similar approach for reading in tab-delimited
or
  single space delimited data? Example data:
 
  data3-
  OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL AGEGROUP
  21 76 M 84 5 3.2 0.9 3
  22 76 M  5 2.18 0.84 3
  23 68 M 82 5 2.15 0.52 1
  24 69 M 84 5 2.3 1.36 1
  25 76 F 100 3 25.3 1.07 3
 

Re: [R] Reading in tab (and space) delimited data within a scriptXXXX

2012-01-19 Thread Daniel Nordlund
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Dan Abner
 Sent: Thursday, January 19, 2012 8:51 AM
 To: R. Michael Weylandt
 Cc: r-help@r-project.org
 Subject: Re: [R] Reading in tab (and space) delimited data within a
 script
 
 Hi Michael,
 
 Thanks for your responses.
 
 When I do this, I am not successful. What am I doing wrong?
 
  data3-
 + OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP
 + 2176M8453.20.93
 + 2276M52.180.843
 + 2368M8252.150.521
 + 2469M8452.31.361
 + 2576F100325.31.073
 + 2670F903200.972
 + 2771F109322.30.942
 + 2870-9965324.31.422
 + 2974F613250.872
 + 3074F62323.30.942
 
 
  data3-read.table(textConnection(data3),
 +header=TRUE,sep= ,
 +row.names=OBSNO)
 Error in data[[rowvar]] : attempt to select less than one element
  closeAllConnections()
  data3
 [1]
 OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP\n2176M8453.20.93\n2276M52.180
 .843\n2368M8252.150.521\n2469M8452.31.361\n2576F100325.31.073\n2670F903200
 .972\n2771F109322.30.942\n2870-
 9965324.31.422\n2974F613250.872\n3074F62323.30.942
 
 
  data3-read.table(textConnection(data3),
 +header=TRUE,sep=\t,
 +row.names=OBSNO)
 Error in data[[rowvar]] : attempt to select less than one element
  closeAllConnections()
  data3
 [1]
 OBSNOAGESEXALKPHOSLABCAMMOLPHOSMMOLAGEGROUP\n2176M8453.20.93\n2276M52.180
 .843\n2368M8252.150.521\n2469M8452.31.361\n2576F100325.31.073\n2670F903200
 .972\n2771F109322.30.942\n2870-
 9965324.31.422\n2974F613250.872\n3074F62323.30.942
 
 
 

Dan,

Reading the data works fine for me on a Win7 x64 system using R-2.14.1 using 
the following.  

data3-
OBSNO AGE SEX ALKPHOS LAB CAMMOL PHOSMMOL AGEGROUP
21 76 M 84 5 3.2 0.9 3
22 76 M  5 2.18 0.84 3
23 68 M 82 5 2.15 0.52 1
24 69 M 84 5 2.3 1.36 1
25 76 F 100 3 25.3 1.07 3
26 70 F 90 3 20 0.97 2
27 71 F 109 3 22.3 0.94 2
28 70 -99 65 3 24.3 1.42 2
29 74 F 61 3 25 0.87 2
30 74 F 62 3 23.3 0.94 2

df - read.table(textConnection(data3), header=TRUE, sep=' ', 
na.strings='-99', row.names='OBSNO')

Something may have become corrupted on your system.  Try restarting R and 
re-running the code.  If that doesn't solve the problem, then you may need to 
show us exactly the code you are executing, and provide relevant information 
about your OS and version of R with sessionInfo().

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA

__
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] Filling color's points in legend's plot in R

2012-01-19 Thread R. Michael Weylandt
You might be able to do it with overplotting,(i.e., do the solid grey
using the pch values in the 20s and then use a hollow symbol to put a
black border on it) but I don't see a natural way to change the
background color for just those characters. How'd you do so on the
body of the plot?

examples(legend)

might also have some useful tricks.

Michael

2012/1/19 Uwe Ligges lig...@statistik.tu-dortmund.de:


 On 19.01.2012 15:02, Tsidkenu wrote:

 Thanks for the reply but I want to color (of gray) the triangle, square,
 circle and the other symbol appear in the legend.


 PLEASE do read the posting guide.

 Uwe Ligges





 --
 View this message in context:
 http://r.789695.n4.nabble.com/Filling-color-s-points-in-legend-s-plot-in-R-tp4308966p4310070.html
 Sent from the R help mailing list archive at Nabble.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.


 __
 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] Executable Expressions II

2012-01-19 Thread R. Michael Weylandt
Glad you got it worked out -- I don't know C# but if it's portable-ish
to C++ you may also want to look at Dirk's RInside project:

http://dirk.eddelbuettel.com/code/rinside.html

and here in web-deployment

http://dirk.eddelbuettel.com/blog/2011/11/30/#rinside_and_wt

Michael

On Wed, Jan 18, 2012 at 5:23 PM, Ajay Askoolum aa2e...@yahoo.co.uk wrote:
 I am not using RExcel at all.

 I have now come up with a better solution that using eval. I can construct 
 the data structure (like c(1,2,3,4,5)) as an object in C# and pass it as the 
 argument to the method inside the web service that will call R. Works fine.
        [[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-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] fitting an exp model

2012-01-19 Thread Ben Bolker
arivald rzepus.m at gmail.com writes:

 I am trying to fit an exponential model using nls to some data. 
 
 #data 
 t - c(0,15,30,60,90,120,240,360,480)
 var - c(0.36,9.72,15.50,23.50,31.44,40.66,59.81,73.11,81.65)
 df - data.frame(t, var)
 
 # model  
 # var ~ a+b*(1-exp(-k*t))
 
 # I'm looking for values of a,b and k
 
 #  formula 
 #  mod - nls(formula = var ~ a+b *(1-exp((-k)*t)), start=list(a=0, b=10,
 k=0), trace=T)
 
 # It fails and I get the following error - 
 Error in nlsModel(formula, mf, start, wts) : 
   singular gradient matrix at initial parameter estimates 
 

  Try different starting values, especially with k0 ?


mod2 - nls(formula = var ~ a+b *(1-exp((-k)*t)),
start=list(a=0, b=10,k=0.01), trace=TRUE)

Alternately you can try a self-starting model (see ?SSasymp),
although the parameterization is a little different.

mod3 - nls(formula = var ~ SSasymp(t,b,a,lrc), trace=TRUE)
coef(mod2)
coef(mod3)
with(as.list(coef(mod3)),c(a=a,b=b-a,k=exp(lrc)))

__
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] read in Stata and SPSS with value labels/formats

2012-01-19 Thread Xu Jun
Sorry I forgot the subject line last time

Dear R experts,

I am using the foreign package to read in Stata and SPSS format data
files (same data but I tried different format). I first tried using
read.dta for the Stata format:


##
 library(foreign)
 mystata - read.dta(data/hlthintl.dta, convert.factor=FALSE)
Error in read.dta(data/hlthintl.dta, convert.factor = FALSE) :
 a binary read error occurred
##

Then I tried saving this Stata file to an old version without labels in Stata

use data\hlthintl.dta, clear
saveold data\hlthintlold.dta, nolabel


Then I read the hlthintlold.dta into R without problems, but of course
without value labels. Well, to keep these value labels, I turned to
SPSS. Here is what I did and got:

#
myspss - read.spss(data/hlthintl.sav, use.value.labels=TRUE, 
max.value.labels=Inf, to.data.frame=TRUE)
There were 50 or more warnings (use warnings() to see the first 50)
 warnings()
Warning messages:
1: In read.spss(data/hlthintl.sav,  ... :
 data/hlthintl.sav: File contains duplicate label for value 276.2 for
variable V4
2: In read.spss(data/hlthintl.sav,  ... :
 data/hlthintl.sav: File contains duplicate label for value 376.2 for
variable V4
3: In read.spss(data/hlthintl.sav,  ... :
 data/hlthintl.sav: File contains duplicate label for value 826.2 for
variable V4
4: In xi = z[1L] | xi = z[2L] | xi[xi == z[3L]] :
 longer object length is not a multiple of shorter object length
5
6
...
...
50.



Warnings 5-50 are the same as warning 4. Now I can have most data
transferred into the R system correctly except when I check an
occupation variable, it lost all its numeric coding (frequencies are
all zero)



 table(myspss$occupation)

                                               ARMED FORCES
                                                          0
                                                   Soldiers
                                                          0
                                                   Officers
                                                          0
...
...
...
...

             Hand packers and other manufacturing labourers
                                                          0
                   TRANSPORT LABOURERS AND FREIGHT HANDLERS
                                                          0
                              Hand or pedal vehicle drivers
                                                          0
             Drivers of animal-drawn vehicles and machinery
                                                          0
                                           Freight handlers
                                                          0
                                                    Refused
                                                          0
                                                  Dont know
                                                          0
Warning message:
In `levels-`(`*tmp*`, value = c(ARMED FORCES, Soldiers, Officers,  :
 duplicated levels will not be allowed in factors anymore


Any thoughts or suggestions? Thanks a lot!

Jun Xu, PhD
Assistant Professor
Department of Sociology
Ball State University

__
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] Executable Expressions II

2012-01-19 Thread Ajay Askoolum
Thank you very much for this information.




 From: R. Michael Weylandt michael.weyla...@gmail.com

Cc: Richard M. Heiberger r...@temple.edu; R General Forum 
r-help@r-project.org 
Sent: Thursday, 19 January 2012, 19:17
Subject: Re: [R] Executable Expressions II

Glad you got it worked out -- I don't know C# but if it's portable-ish
to C++ you may also want to look at Dirk's RInside project:

http://dirk.eddelbuettel.com/code/rinside.html

and here in web-deployment

http://dirk.eddelbuettel.com/blog/2011/11/30/#rinside_and_wt

Michael


 I am not using RExcel at all.

 I have now come up with a better solution that using eval. I can construct 
 the data structure (like c(1,2,3,4,5)) as an object in C# and pass it as the 
 argument to the method inside the web service that will call R. Works fine.
        [[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] drop rare factors

2012-01-19 Thread Sam Steingold
 * Sarah Goslee fnenu.tbf...@tznvy.pbz [2012-01-18 17:36:16 -0500]:

 Here's one way, worked out in lots of steps so you can see
 how each works:

thanks, it all makes perfect sense, and I wrote this function based on
your instructions:

drop.levels - function (frame, column, threshold) {
  size - nrow(frame)
  if (threshold  1) threshold - threshold * size
  tab - table(frame[column])
  keep - names(tab)[tab   threshold]
  drop - names(tab)[tab = threshold]
  cat(Keep(,column,),length(keep)); print(tab[keep])
  cat(Drop(,column,),length(drop)); print(tab[drop])
  frame1 - frame[frame[column] %in% keep, ]
  size1 - nrow(frame1)
  cat(Rows:,size,--,size1,(dropped,100*(size-size1)/size,%)\n)
  frame1[column] - factor(frame1[column], levels=keep)
  frame1
}

alas, I get an error:

Rows: 87392 -- 0 (dropped 100 %)
Error in `[-.data.frame`(`*tmp*`, column, value = NA_integer_) : 
  replacement has 1 rows, data has 0

when I do everything step-by-step interactively it works...

Thanks!

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://ffii.org http://www.PetitionOnline.com/tap12009/ http://camera.org
http://palestinefacts.org http://jihadwatch.org http://pmw.org.il
Your mouse has moved - WinNT has to be restarted for this to take effect.

__
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] What is a 'closure'?

2012-01-19 Thread Ajay Askoolum
The R Language Definition at 
http://cran.r-project.org/doc/manuals/R-lang.html states in the following 
section 

4.3.2 Argument matching
This subsection applies to closures but not to primitive functions.

What are 'closures'?
[[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] drop rare factors

2012-01-19 Thread Sarah Goslee
Hi Sam,

To be of any use whatsoever, we need a reproducible example.

What's frame?
What's column?
What's threshold?

Remind the list what you're trying to do. The list gets lots of traffic;
if you delete out all the context nobody will remember what you need.

Sarah

On Thu, Jan 19, 2012 at 2:44 PM, Sam Steingold s...@gnu.org wrote:
 * Sarah Goslee fnenu.tbf...@tznvy.pbz [2012-01-18 17:36:16 -0500]:

 Here's one way, worked out in lots of steps so you can see
 how each works:

 thanks, it all makes perfect sense, and I wrote this function based on
 your instructions:

 drop.levels - function (frame, column, threshold) {
  size - nrow(frame)
  if (threshold  1) threshold - threshold * size
  tab - table(frame[column])
  keep - names(tab)[tab   threshold]
  drop - names(tab)[tab = threshold]
  cat(Keep(,column,),length(keep)); print(tab[keep])
  cat(Drop(,column,),length(drop)); print(tab[drop])
  frame1 - frame[frame[column] %in% keep, ]
  size1 - nrow(frame1)
  cat(Rows:,size,--,size1,(dropped,100*(size-size1)/size,%)\n)
  frame1[column] - factor(frame1[column], levels=keep)
  frame1
 }

 alas, I get an error:

 Rows: 87392 -- 0 (dropped 100 %)
 Error in `[-.data.frame`(`*tmp*`, column, value = NA_integer_) :
  replacement has 1 rows, data has 0

 when I do everything step-by-step interactively it works...

 Thanks!


-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] What is a 'closure'?

2012-01-19 Thread R. Michael Weylandt
http://www.lemnica.com/esotericR/Introducing-Closures/

Any function you work with will be a closure -- primitives are
built-in functions that users can't create. (without source editing 
recompiling R) E.g. the function c() (type it without parentheses at
the prompt to see its code)

Let me know if I can explain more,

Michael

On Thu, Jan 19, 2012 at 2:45 PM, Ajay Askoolum aa2e...@yahoo.co.uk wrote:
 The R Language Definition at 
 http://cran.r-project.org/doc/manuals/R-lang.html states in the following 
 section

 4.3.2 Argument matching
 This subsection applies to closures but not to primitive functions.

 What are 'closures'?
        [[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-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] Alaska and Hawaii map data?

2012-01-19 Thread Ray Brownrigg
On Fri, 20 Jan 2012, Kevin Burton wrote:
 I can plot each county of the contiguous 48 states or all of them using
 variations of
 
 
 
 map('county', region=c('wisconsin' . . . .)
 
 
 
 in the maps package. I was wondering whether similar data was available for
 Alaska and Hawaii? I was also wondering if there was a database that listed
 FIPS codes for the counties in Alaska and Hawaii. Similar to 'county.fips'.
 
None of these is part of the maps package.  Sorry.

The good news is that maps is a *source* package, so if you need new 
functionality, you 
are quite at liberty to add it yourself.

Further, there are other mapping (and more general 'spatial') packages 
available, that may 
provide such functionality.  See the CRAN spatial taskview at:
http://cran.r-project.org/web/views/Spatial.html

Ray Brownrigg
 
 
 Thank you.
 
 
 
 Kevin Burton
 
 
   [[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-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] fitting an exp model

2012-01-19 Thread Rolf Turner

On 20/01/12 06:38, arivald wrote:

Hello there,

I am trying to fit an exponential model using nls to some data.

#data
t- c(0,15,30,60,90,120,240,360,480)
var- c(0.36,9.72,15.50,23.50,31.44,40.66,59.81,73.11,81.65)
df- data.frame(t, var)

# model
# var ~ a+b*(1-exp(-k*t))

# I'm looking for values of a,b and k

#  formula
#  mod- nls(formula = var ~ a+b *(1-exp((-k)*t)), start=list(a=0, b=10,
k=0), trace=T)

# It fails and I get the following error -
Error in nlsModel(formula, mf, start, wts) :
   singular gradient matrix at initial parameter estimates

I was trying different methods and looking for some solutions but nothing is
working...

Any suggestions how I can fix this? I appreciated any help
Thanks in advance.


Try different starting values.  Yours are out to lunch.  Look at:

plot(function(t){10*(1-exp(-t))},xlim=c(0,500),xlab=t,ylab=var)

This goes to hell in a handcart at about t=6 and looks nothing like

plot(t,var)

I found that

mod - nls(formula = var ~ a + b *(1-exp((-k)*t)), 
start=list(a=0,b=80, k=0.01))


works OK.  Then doing

ccc - coef(mod)
plot(function(t){ccc[1] 
+ccc[2]*(1-exp(-ccc[3]*t))},xlim=c(0,500),xlab=t,ylab=var)

points(t,var)

indicates a fairly reasonable fit.  One wonders however about the 
validity of the model

considering the lack of  fit at t=0.

R has great and easy-to-use graphics capabilities.  Use them!

cheers,

Rolf Turner

__
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] What is a 'closure'?

2012-01-19 Thread Ajay Askoolum
Michael, thank you, especially for the link. I think I understand.

The vocabulary is so different! I know 'closure' as 'user-defined function'.

[[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] What is a 'closure'?

2012-01-19 Thread Ben Bolker
Ajay Askoolum aa2e72e at yahoo.co.uk writes:

 
 Michael, thank you, especially for the link. I think I understand.
 
 The vocabulary is so different! I know 'closure' as 'user-defined function'.
 

  Not quite.  All (??) user-defined functions are closures, but lots
of non-user-defined functions are closures too ...

 typeof(mean)
[1] closure
 typeof(sum)
[1] builtin
 typeof(apply)
[1] closure

__
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] drop rare factors

2012-01-19 Thread Sam Steingold
create data:

mydata - data.frame(MyFactor = factor(rep(LETTERS[1:4], times=c(1000, 2000, 
30, 4))), something = runif(3034))

define function:

drop.levels - function (df, column, threshold) {
  size - nrow(df)
  if (threshold  1) threshold - threshold * size
  tab - table(df[column])
  keep - names(tab)[tab   threshold]
  drop - names(tab)[tab = threshold]
  cat(Keep(,column,),length(keep),\n); print(tab[keep])
  cat(Drop(,column,),length(drop),\n); print(tab[drop])
  str(df)
  df - df[df[column] %in% keep, ]
  str(df)
  size1 - nrow(df)
  cat(Rows:,size,--,size1,(dropped,100*(size-size1)/size,%)\n)
  df[column] - factor(df[column], levels=keep)
  df
}

call the function on the data:

drop.levels(mydata,MyFactor,5)
Keep( MyFactor ) 3 

   ABC 
1000 2000   30 
Drop( MyFactor ) 1 
D 
4 
'data.frame':   3034 obs. of  2 variables:
 $ MyFactor : Factor w/ 4 levels A,B,C,D: 1 1 1 1 1 1 1 1 1 1 ...
 $ something: num  0.725 0.741 0.608 0.681 0.993 ...
'data.frame':   0 obs. of  2 variables:
 $ MyFactor : Factor w/ 4 levels A,B,C,D: 
 $ something: num 
Rows: 3034 -- 0 (dropped 100 %)
Error in `[-.data.frame`(`*tmp*`, column, value = NA_integer_) : 
  replacement has 1 rows, data has 0

- why is there a blank line between Keep( MyFactor ) 3 and ABC
 but no blank line between Drop and D?

- why does df[df[column] %in% keep, ] empty out the data frame?

thanks!


 Remind the list what you're trying to do. The list gets lots of traffic;
 if you delete out all the context nobody will remember what you need.

Sorry, I assumed that people can easily access the parent messages.

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000
http://www.PetitionOnline.com/tap12009/ http://pmw.org.il
http://mideasttruth.com http://memri.org http://openvotingconsortium.org
Syntactic sugar causes cancer of the semicolon.   -Alan Perlis

__
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] POSIXct value display incorrect for some values

2012-01-19 Thread Curt Seeliger
First, the reproducable example, showing how converting from character to 
POSIXct to character changes the milliseconds in the first time stamp 
though not in the second:

 as.POSIXct('2010-06-03 9:03:58.324')
[1] 2010-06-03 09:03:58.323 PDT

 as.POSIXct('2010-06-03 9:03:58.325')
[1] 2010-06-03 09:03:58.325 PDT

This seems to be due to truncation of the numeric value of the POSIX 
object during conversion to character:

 as.numeric(as.POSIXct('2010-06-03 9:03:58.324'))
[1] 1275581038.3239998817

Neither format() nor round() seem to be of assistance here.  Anyone got a 
solution?

 as.POSIXct(round(as.double(as.POSIXct('2010-06-03 09:03:58.324')), 
digits=3), origin=(as.POSIXct('1970-01-01')))
[1] 2010-06-03 17:03:58.323 PDT
 format(as.POSIXct('2010-06-03 09:03:58.324'), %Y-%m-%d %H:%M:%OS4)
[1] 2010-06-03 09:03:58.3239

Thanks,
cur
-- 
Curt Seeliger, Data Ranger
Raytheon Information Services - Contractor to ORD
seeliger.c...@epa.gov
541/754-4638

[[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] drop rare factors

2012-01-19 Thread Sarah Goslee
Everywhere that you use
df[column]

should be

df[[column]]

That's the only thing I see, *except* that df() and drop() are base functions,
so you shouldn't use those as variable names.

 Remind the list what you're trying to do. The list gets lots of traffic;
 if you delete out all the context nobody will remember what you need.

 Sorry, I assumed that people can easily access the parent messages.

I at least don't save the entire R-help archive in my inbox. And if
you're asking
folks for help, why not make it easy for them?

Next time, please follow the posting guide and include context.

Sarah


On Thu, Jan 19, 2012 at 3:43 PM, Sam Steingold s...@gnu.org wrote:
 create data:

 mydata - data.frame(MyFactor = factor(rep(LETTERS[1:4], times=c(1000, 2000, 
 30, 4))), something = runif(3034))

 define function:

 drop.levels - function (df, column, threshold) {
  size - nrow(df)
  if (threshold  1) threshold - threshold * size
  tab - table(df[column])
  keep - names(tab)[tab   threshold]
  drop - names(tab)[tab = threshold]
  cat(Keep(,column,),length(keep),\n); print(tab[keep])
  cat(Drop(,column,),length(drop),\n); print(tab[drop])
  str(df)
  df - df[df[column] %in% keep, ]
  str(df)
  size1 - nrow(df)
  cat(Rows:,size,--,size1,(dropped,100*(size-size1)/size,%)\n)
  df[column] - factor(df[column], levels=keep)
  df
 }

 call the function on the data:

 drop.levels(mydata,MyFactor,5)
 Keep( MyFactor ) 3

   A    B    C
 1000 2000   30
 Drop( MyFactor ) 1
 D
 4
 'data.frame':   3034 obs. of  2 variables:
  $ MyFactor : Factor w/ 4 levels A,B,C,D: 1 1 1 1 1 1 1 1 1 1 ...
  $ something: num  0.725 0.741 0.608 0.681 0.993 ...
 'data.frame':   0 obs. of  2 variables:
  $ MyFactor : Factor w/ 4 levels A,B,C,D:
  $ something: num
 Rows: 3034 -- 0 (dropped 100 %)
 Error in `[-.data.frame`(`*tmp*`, column, value = NA_integer_) :
  replacement has 1 rows, data has 0

 - why is there a blank line between Keep( MyFactor ) 3 and A    B    C
  but no blank line between Drop and D?

 - why does df[df[column] %in% keep, ] empty out the data frame?

 thanks!


 Remind the list what you're trying to do. The list gets lots of traffic;
 if you delete out all the context nobody will remember what you need.

 Sorry, I assumed that people can easily access the parent messages.



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] drop rare factors

2012-01-19 Thread William Dunlap
 That's the only thing I see, *except* that df() and drop() are base functions,
 so you shouldn't use those as variable names.

I don't think that is much of a problem.  The local
versions will be used in the function.

A bigger problem is naming your function 'drop.levels'.
There is a core R function called 'droplevels' that drops
unused levels from factors.  I would hate to have to
remember the difference between the dotted and dotless
versions.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf Of Sarah Goslee
 Sent: Thursday, January 19, 2012 1:01 PM
 To: s...@gnu.org; Sarah Goslee; r-help@r-project.org
 Subject: Re: [R] drop rare factors
 
 Everywhere that you use
 df[column]
 
 should be
 
 df[[column]]
 
 That's the only thing I see, *except* that df() and drop() are base functions,
 so you shouldn't use those as variable names.
 
  Remind the list what you're trying to do. The list gets lots of traffic;
  if you delete out all the context nobody will remember what you need.
 
  Sorry, I assumed that people can easily access the parent messages.
 
 I at least don't save the entire R-help archive in my inbox. And if
 you're asking
 folks for help, why not make it easy for them?
 
 Next time, please follow the posting guide and include context.
 
 Sarah
 
 
 On Thu, Jan 19, 2012 at 3:43 PM, Sam Steingold s...@gnu.org wrote:
  create data:
 
  mydata - data.frame(MyFactor = factor(rep(LETTERS[1:4], times=c(1000, 
  2000, 30, 4))), something =
 runif(3034))
 
  define function:
 
  drop.levels - function (df, column, threshold) {
   size - nrow(df)
   if (threshold  1) threshold - threshold * size
   tab - table(df[column])
   keep - names(tab)[tab   threshold]
   drop - names(tab)[tab = threshold]
   cat(Keep(,column,),length(keep),\n); print(tab[keep])
   cat(Drop(,column,),length(drop),\n); print(tab[drop])
   str(df)
   df - df[df[column] %in% keep, ]
   str(df)
   size1 - nrow(df)
   cat(Rows:,size,--,size1,(dropped,100*(size-size1)/size,%)\n)
   df[column] - factor(df[column], levels=keep)
   df
  }
 
  call the function on the data:
 
  drop.levels(mydata,MyFactor,5)
  Keep( MyFactor ) 3
 
    A    B    C
  1000 2000   30
  Drop( MyFactor ) 1
  D
  4
  'data.frame':   3034 obs. of  2 variables:
   $ MyFactor : Factor w/ 4 levels A,B,C,D: 1 1 1 1 1 1 1 1 1 1 ...
   $ something: num  0.725 0.741 0.608 0.681 0.993 ...
  'data.frame':   0 obs. of  2 variables:
   $ MyFactor : Factor w/ 4 levels A,B,C,D:
   $ something: num
  Rows: 3034 -- 0 (dropped 100 %)
  Error in `[-.data.frame`(`*tmp*`, column, value = NA_integer_) :
   replacement has 1 rows, data has 0
 
  - why is there a blank line between Keep( MyFactor ) 3 and A    B    
  C
   but no blank line between Drop and D?
 
  - why does df[df[column] %in% keep, ] empty out the data frame?
 
  thanks!
 
 
  Remind the list what you're trying to do. The list gets lots of traffic;
  if you delete out all the context nobody will remember what you need.
 
  Sorry, I assumed that people can easily access the parent messages.
 
 
 
 --
 Sarah Goslee
 http://www.functionaldiversity.org
 
 __
 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] What is a 'closure'?

2012-01-19 Thread Ajay Askoolum


Thanks for clarifying.

Is my (new) understanding stated below correct?

- A closure is any function (user- or system- defined) where 
is.primitive(functionName) is FALSE. 

- is.primitive(functionName) is FALSE when functionName is a system-defined 
function that is coded in R itself.
[[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] drop rare factors

2012-01-19 Thread Sarah Goslee
On Thu, Jan 19, 2012 at 4:11 PM, William Dunlap wdun...@tibco.com wrote:
 That's the only thing I see, *except* that df() and drop() are base 
 functions,
 so you shouldn't use those as variable names.

 I don't think that is much of a problem.  The local
 versions will be used in the function.

Yes, but somewhere in the series of emails the original querent was talking
about running the function line by line to see if each bit worked, a common
debugging method. It's generally safer to not use base functions as
names (see the many questions to the list due to using c as a name).
(Or actually, I'm not entirely certain that's what he meant, but that's how
interpreted one of the vague statements.)

 A bigger problem is naming your function 'drop.levels'.
 There is a core R function called 'droplevels' that drops
 unused levels from factors.  I would hate to have to
 remember the difference between the dotted and dotless
 versions.

Definitely confusing if this ever gets used beyond the single
person who wrote it.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] What is a 'closure'?

2012-01-19 Thread peter dalgaard

On Jan 19, 2012, at 21:39 , Ben Bolker wrote:

 Ajay Askoolum aa2e72e at yahoo.co.uk writes:
 
 
 Michael, thank you, especially for the link. I think I understand.
 
 The vocabulary is so different! I know 'closure' as 'user-defined function'.
 
 
  Not quite.  All (??) user-defined functions are closures, but lots
 of non-user-defined functions are closures too ...
 

Also, it is not actually the function that is the closure, it is the function 
completed with its environment, which is where, during evaluation, unbound 
objects will be sought.

The function itself is a parsed version of the function definition. When 
called, almost all functions will need to find something from their 
environment, e.g. the - operator. The only functions that are completely 
self-contained are those that return a constant or one of the function 
arguments (maybe a few more). 

-- 
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] What is a 'closure'?

2012-01-19 Thread Bert Gunter
On Thu, Jan 19, 2012 at 1:15 PM, Ajay Askoolum aa2e...@yahoo.co.uk wrote:


 Thanks for clarifying.

 Is my (new) understanding stated below correct?

No.

-- Bert

 - A closure is any function (user- or system- defined) where 
 is.primitive(functionName) is FALSE.

 - is.primitive(functionName) is FALSE when functionName is a system-defined 
 function that is coded in R itself.
        [[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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
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] computing scores from a factor analysis

2012-01-19 Thread William Revelle
Wolfgang, 

Since you seem to be doing this in the psych package, it would have been faster 
to directly ask the author (me).  Luckily, I saw the question on R-Help.
 

The principal components step is being done on the correlation matrix, not on 
the raw data matrix, thus, it is not able to find scores.

However, since you have the components solution, you also the scoring weights.

Taking your analysis:

 tetra - tetrachoric (image_na, correct=TRUE)
 t_matrix - tetra$rho
 pca.tetra - principal(t_matrix, nfactors = 10, n.obs = nrow(image_na),
 rotate=varimax, scores=FALSE)

scores - image_na %*% pca.tetra$weights

Bill






On Jan 18, 2012, at 4:27 AM, wolfgang wrote:

 Haj
 
 i try to perform a principal component analysis by using a tetrachoric
 correlation matrix as data input
 
 tetra - tetrachoric (image_na, correct=TRUE)
 t_matrix - tetra$rho
 pca.tetra - principal(t_matrix, nfactors = 10, n.obs = nrow(image_na),
 rotate=varimax, scores=TRUE)
 
 the problem i have is to compute the individual factor scores from the pca.
 the code runs perfect if i do not ask for the scores
 
 if i ask for the scores i get an error message
 Error in scale(x.matrix): object 'x.matrix' not found
 
 can somebody help me?
 
 cheers
 wolfgang
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/computing-scores-from-a-factor-analysis-tp4306234p4306234.html
 Sent from the R help mailing list archive at Nabble.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.
 

William Revellehttp://personality-project.org/revelle.html
Professor  http://personality-project.org
Department of Psychology   http://www.wcas.northwestern.edu/psych/
Northwestern Universityhttp://www.northwestern.edu/
Use R for psychology http://personality-project.org/r
It is 5 minutes to midnighthttp://www.thebulletin.org

__
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] read in Stata and SPSS with value labels/formats

2012-01-19 Thread Frank Harrell
require(Hmisc)
?spss.get

Xu Jun wrote
 
 Sorry I forgot the subject line last time
 
 Dear R experts,
 
 I am using the foreign package to read in Stata and SPSS format data
 files (same data but I tried different format). I first tried using
 read.dta for the Stata format:
 
 
 ##
 library(foreign)
 mystata - read.dta(data/hlthintl.dta, convert.factor=FALSE)
 Error in read.dta(data/hlthintl.dta, convert.factor = FALSE) :
  a binary read error occurred
 ##
 
 Then I tried saving this Stata file to an old version without labels in
 Stata
 
 use data\hlthintl.dta, clear
 saveold data\hlthintlold.dta, nolabel
 
 
 Then I read the hlthintlold.dta into R without problems, but of course
 without value labels. Well, to keep these value labels, I turned to
 SPSS. Here is what I did and got:
 
 #
myspss - read.spss(data/hlthintl.sav, use.value.labels=TRUE,
max.value.labels=Inf, to.data.frame=TRUE)
 There were 50 or more warnings (use warnings() to see the first 50)
 warnings()
 Warning messages:
 1: In read.spss(data/hlthintl.sav,  ... :
  data/hlthintl.sav: File contains duplicate label for value 276.2 for
 variable V4
 2: In read.spss(data/hlthintl.sav,  ... :
  data/hlthintl.sav: File contains duplicate label for value 376.2 for
 variable V4
 3: In read.spss(data/hlthintl.sav,  ... :
  data/hlthintl.sav: File contains duplicate label for value 826.2 for
 variable V4
 4: In xi = z[1L] | xi = z[2L] | xi[xi == z[3L]] :
  longer object length is not a multiple of shorter object length
 5
 6
 ...
 ...
 50.
 
 
 
 Warnings 5-50 are the same as warning 4. Now I can have most data
 transferred into the R system correctly except when I check an
 occupation variable, it lost all its numeric coding (frequencies are
 all zero)
 
 
 
 table(myspss$occupation)
 
                                                ARMED FORCES
                                                           0
                                                    Soldiers
                                                           0
                                                    Officers
                                                           0
 ...
 ...
 ...
 ...
 
              Hand packers and other manufacturing labourers
                                                           0
                    TRANSPORT LABOURERS AND FREIGHT HANDLERS
                                                           0
                               Hand or pedal vehicle drivers
                                                           0
              Drivers of animal-drawn vehicles and machinery
                                                           0
                                            Freight handlers
                                                           0
                                                     Refused
                                                           0
                                                   Dont know
                                                           0
 Warning message:
 In `levels-`(`*tmp*`, value = c(ARMED FORCES, Soldiers, Officers,
  :
  duplicated levels will not be allowed in factors anymore
 
 
 Any thoughts or suggestions? Thanks a lot!
 
 Jun Xu, PhD
 Assistant Professor
 Department of Sociology
 Ball State University
 
 __
 R-help@ 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.
 


-
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: 
http://r.789695.n4.nabble.com/read-in-Stata-and-SPSS-with-value-labels-formats-tp4311210p4311751.html
Sent from the R help mailing list archive at Nabble.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.


[R] Establishing groups using something other than ifelse()

2012-01-19 Thread Sam Albers
Hello all,

This is one of those Is there a better way to do this questions. Say
I have a dataframe (df) with a grouping variable (z). This is my base
data. Now I know that there is a higher order level of grouping that
exist for my group variable. So what I want to do is create a new
column that express that higher order level of grouping based on
values in the sub-group (z  in this case). In the past I have used
ifelse() but this tends to get fairly redundant and messy with a large
amount of sub-groupings (z). I've created a sample dataset below. Can
anyone recommend a better way of achieving what I am currently
achieving with ifelse()? A long series of ifelse statements makes me
think that there is something better for this.

## Dataframe creation
df - data.frame(x=runif(36, 0, 120),
   y=runif(36, 0, 120),

z=factor(c(A1,A1,A2,A2,B1,B1,B2,B2,C1,C,C2,C2))
   )

## Current method is grouping
df$Big.Group - with(df, ifelse(df$z==A1,A, ifelse(df$z==A2,A,
ifelse(df$z==B1, B, ifelse(df$z==B2, B, C)


So any suggestions? Thanks in advance!

Sam

__
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] Establishing groups using something other than ifelse()

2012-01-19 Thread Justin Haynes
how bout

levels(df$z)[grep('A',levels(df$z))] - 'A'
levels(df$z)[grep('B',levels(df$z))] - 'B'
levels(df$z)[grep('C',levels(df$z))] - 'C'

does that do what you're wanting?


On Thu, Jan 19, 2012 at 3:05 PM, Sam Albers tonightstheni...@gmail.comwrote:

 Hello all,

 This is one of those Is there a better way to do this questions. Say
 I have a dataframe (df) with a grouping variable (z). This is my base
 data. Now I know that there is a higher order level of grouping that
 exist for my group variable. So what I want to do is create a new
 column that express that higher order level of grouping based on
 values in the sub-group (z  in this case). In the past I have used
 ifelse() but this tends to get fairly redundant and messy with a large
 amount of sub-groupings (z). I've created a sample dataset below. Can
 anyone recommend a better way of achieving what I am currently
 achieving with ifelse()? A long series of ifelse statements makes me
 think that there is something better for this.

 ## Dataframe creation
 df - data.frame(x=runif(36, 0, 120),
   y=runif(36, 0, 120),

 z=factor(c(A1,A1,A2,A2,B1,B1,B2,B2,C1,C,C2,C2))
   )

 ## Current method is grouping
 df$Big.Group - with(df, ifelse(df$z==A1,A, ifelse(df$z==A2,A,
 ifelse(df$z==B1, B, ifelse(df$z==B2, B, C)


 So any suggestions? Thanks in advance!

 Sam

 __
 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] What is a 'closure'?

2012-01-19 Thread Hadley Wickham
On Thu, Jan 19, 2012 at 1:45 PM, Ajay Askoolum aa2e...@yahoo.co.uk wrote:
 The R Language Definition at 
 http://cran.r-project.org/doc/manuals/R-lang.html states in the following 
 section

 4.3.2 Argument matching
 This subsection applies to closures but not to primitive functions.

 What are 'closures'?

You might find the discussion here helpful:
https://github.com/hadley/devtools/wiki/First-class-functions

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
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] Establishing groups using something other than ifelse()

2012-01-19 Thread Sam Albers
On Thu, Jan 19, 2012 at 3:34 PM, Justin Haynes jto...@gmail.com wrote:
 how bout

 levels(df$z)[grep('A',levels(df$z))] - 'A'
 levels(df$z)[grep('B',levels(df$z))] - 'B'
 levels(df$z)[grep('C',levels(df$z))] - 'C'

 does that do what you're wanting?

Shoot. Might have made my example confusing, sorry. First of all I
want to retain the information in the sub.group (z) here but more
importantly, I used A1 and A2 to illustrate the grouping under the
larger group A but the pattern of the group names is irrelevant for my
purposes. So to modify the example I wanted to achieve this without
pattern matching like the above:

df - data.frame(x=runif(36, 0, 120),
   y=runif(36, 0, 120),

z=factor(c(G1,G1,G2,G2,H1,H1,H2,H2,I1,I1,I2,I2))
   )

df$Big.Group - with(df, ifelse(df$z==G1,A, ifelse(df$z==G2,A,
ifelse(df$z==H1, B, ifelse(df$z==H2, B, C)

Thanks for the response!

Sam



 On Thu, Jan 19, 2012 at 3:05 PM, Sam Albers tonightstheni...@gmail.com
 wrote:

 Hello all,

 This is one of those Is there a better way to do this questions. Say
 I have a dataframe (df) with a grouping variable (z). This is my base
 data. Now I know that there is a higher order level of grouping that
 exist for my group variable. So what I want to do is create a new
 column that express that higher order level of grouping based on
 values in the sub-group (z  in this case). In the past I have used
 ifelse() but this tends to get fairly redundant and messy with a large
 amount of sub-groupings (z). I've created a sample dataset below. Can
 anyone recommend a better way of achieving what I am currently
 achieving with ifelse()? A long series of ifelse statements makes me
 think that there is something better for this.

 ## Dataframe creation
 df - data.frame(x=runif(36, 0, 120),
                       y=runif(36, 0, 120),

 z=factor(c(A1,A1,A2,A2,B1,B1,B2,B2,C1,C,C2,C2))
                       )

 ## Current method is grouping
 df$Big.Group - with(df, ifelse(df$z==A1,A, ifelse(df$z==A2,A,
 ifelse(df$z==B1, B, ifelse(df$z==B2, B, C)


 So any suggestions? Thanks in advance!

 Sam

 __
 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] Establishing groups using something other than ifelse()

2012-01-19 Thread Jorge I Velez
Hi Sam,

Check the examples in

require(car)
?recode

HTH,
Jorge.-


On Thu, Jan 19, 2012 at 6:05 PM, Sam Albers  wrote:

 Hello all,

 This is one of those Is there a better way to do this questions. Say
 I have a dataframe (df) with a grouping variable (z). This is my base
 data. Now I know that there is a higher order level of grouping that
 exist for my group variable. So what I want to do is create a new
 column that express that higher order level of grouping based on
 values in the sub-group (z  in this case). In the past I have used
 ifelse() but this tends to get fairly redundant and messy with a large
 amount of sub-groupings (z). I've created a sample dataset below. Can
 anyone recommend a better way of achieving what I am currently
 achieving with ifelse()? A long series of ifelse statements makes me
 think that there is something better for this.

 ## Dataframe creation
 df - data.frame(x=runif(36, 0, 120),
   y=runif(36, 0, 120),

 z=factor(c(A1,A1,A2,A2,B1,B1,B2,B2,C1,C,C2,C2))
   )

 ## Current method is grouping
 df$Big.Group - with(df, ifelse(df$z==A1,A, ifelse(df$z==A2,A,
 ifelse(df$z==B1, B, ifelse(df$z==B2, B, C)


 So any suggestions? Thanks in advance!

 Sam

 __
 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] Bayesian data analysis recommendations

2012-01-19 Thread C W
Dear all,
I am trying to learn Bayesian inference and Bayesian data analysis, I
am new in the field.  Would any experts on the list recommend any good
sites or materials for beginners?

My approach is to learn and understand the theory first, then program
on my own using R, though I see there are already packages.

appreciate any help, thanks in advance!

__
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] snow - bootstrapped correlation ranking

2012-01-19 Thread Patrik Waldmann
I wonder if someone could help me adjusting the following code to parallelized 
snow code:

#Creating a data set (not needed to be parallel)
n-100
p-100
x-matrix(rnorm(n*p),p)
y-rnorm(n)
# Bootstrapping
nboot-1000
alpha-0.05
rhoboot - array(0, dim=c(p,nboot))
bootranks - array(0, dim=c(p,nboot))
bootsamples - array( floor(runif(n*nboot)*n+1), dim=c(n,nboot))
for (i in 1:nboot){
rhoboot[,i] - cor(y[bootsamples[,i]],x[bootsamples[,i],])
bootranks[,i] - p+1rank(abs(rhoboot[,i]))
}
# Summarise results
rankhigh = apply(bootranks, 1, quantile, probs=alpha/2)
ranklow = apply(bootranks, 1, quantile, probs=1-alpha/2)


Patrik Waldmann

[[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] question re. package playwith not able to run command getting error message that I'm attempting to use non function

2012-01-19 Thread Farhat Maha
Hello, I managed to install playwith package and all its prerequisites. My
R version is R 2.14:

R version 2.14.1 (2011-12-22)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i486-pc-linux-gnu (32-bit)

All my packages were updated, and recently installed. When I attempt
to use the command playwith I get the following error message:


 library(playwith)
Loading required package: lattice
Loading required package: cairoDevice
Loading required package: gWidgetsRGtk2
Loading required package: gWidgets
Loading required package: grid

 playwith(plot(1:10))
Error in playwith(plot(1:10)) : attempt to apply non-function

 playwith(xyplot(Income ~ log(Population / Area),
+data = data.frame(state.x77), groups = state.region,
+type = c(p, smooth), span = 1, auto.key = TRUE,
+xlab = Population density, 1974 (log scale),
+ylab = Income per capita, 1974)
+ )
Error in playwith(xyplot(Income ~ log(Population/Area), data =
data.frame(state.x77),  :
  attempt to apply non-function

 interactive()
[1] TRUE

 autoplay(on = TRUE, lattice.on = TRUE, base.on = TRUE, grid.on = TRUE, ask = 
 FALSE)
Automatic `playwith` for Lattice graphics is now ON.
Automatic `playwith` for base graphics is now ON.
Automatic `playwith` for grid graphics is now ON.
 plot(1:10)
Error in playwith(plot(1:10), envir = environment) :
  attempt to apply non-function
Error in plot.xy(xy, type, ...) : plot.new has not been called yet



Any advice about why it is not working.
thanks
Maha

[[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] dataframe: how to select an element from a row

2012-01-19 Thread ikuzar
Hi, 
I 'd like to select the Date where myvalue =1800 appears the* first time*.

For instance:
df =data.frame(date, myvalue, ...)

...

Datemyvalue
2012-01-052500
2012-01-06   2450
*2012-01-07   1800*
2012-01-082200
2012-01-091800

I'd like to retrieve the third line.

I do not find a clean way.

Thanks for your help



--
View this message in context: 
http://r.789695.n4.nabble.com/dataframe-how-to-select-an-element-from-a-row-tp4311881p4311881.html
Sent from the R help mailing list archive at Nabble.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.


[R] Apply Function to List by Group Returning Result with Dim of List

2012-01-19 Thread jamesrobinsonjnr
I have a panel data set defined as a simple data.frame with a factor age and
income. I would like to generate the results of a set function such as (sum,
mean, or even diff) separate for each factor (category or age group).
However I want the result to have the same dimension as the overal
data.frame. Therefore, I expect to get repeaded the same result for each
item within a category, but different accross categories. 

Eg:
ageincomeavg_inc
20 100   100
20   90   100  
20 110   100
30  200  200
30  250  200
30  150  200

What builtin function can assist in doing this without my having to write
loops. I know in Eviews there is the sumsby, meansby, minsby and so forth.

--
View this message in context: 
http://r.789695.n4.nabble.com/Apply-Function-to-List-by-Group-Returning-Result-with-Dim-of-List-tp4311880p4311880.html
Sent from the R help mailing list archive at Nabble.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.


  1   2   >