[R] elegant way to check if 2 values are in 3 columns?

2011-08-26 Thread Joanne Demmler

Dear all,

I'm trying to rerun some data linkage exercises in R (they are designed 
to be done in SPSS, SAS or STATA)
The exercise in question is to relabel the column treat to 1, if 
yearsep is smaller than 1988 and columns proc1-proc3 contain the 
values 56.36 or 59.81.


My pathetic solution to do this in R currently looks like this:

vaslinks4$treat - 0

vaslinks4$treat[vaslinks4$yearsep  1988  (vaslinks4$proc1 %in% 
c(56.36,59.81)

|| vaslinks4$proc2 %in% c(56.36,59.81)
|| vaslinks4$proc3 %in% c(56.36,59.81))] - 1

But I'm sure there is a more elegant solution for this, in which I would 
not have to call all three columns separately.


Anyone?
Yours Joanne



Solution in SPSS:

COMPUTE treat=0.
FORMATS treat (F1).
DO REPEAT proc=proc1 to proc3.
DO IF (yearsep LT 1988).
IF (proc EQ 56.36 OR proc EQ 59.81) treat = 1.
END IF.
END REPEAT.

Solution in SAS:

do i = 1 to 3 until (treat  0);
if yearsep  1988 then do;
if procs{i} in (56.36, 59.81) then treat = 1;
else treat = 0;
end;

Solution in STATA:

generate treat=0
foreach x in proc1 proc2 proc3 {
recode treat(0=1) if ((`x'==56.36 | `x'==59.81)  yearsep1988)
| ((`x'=63.70 `x'=63.79)  yearsep=1988)
}
tab treat


--
Joanne Demmler Ph.D.
Research Assistant
College of Medicine
Swansea University
Singleton Park
Swansea SA2 8PP
UK
tel:+44 (0)1792 295674
fax:+44 (0)1792 513430
email:  j.demm...@swansea.ac.uk
DECIPHer:   www.decipher.uk.net

__
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] setting up a R working group

2011-03-17 Thread Joanne Demmler

Dear R users,

we are currently trying to set up a R working group at Swansea University.
I would be very grateful to get some information and feedback from R 
users that have done something similar, in particular regarding:


- help with giving a general overview of what R is capable of
- help with what to present or teach (did you organise your own training 
programme or did you get someone from outside?)

- are there people out there who would like to present their work to us?

Any help will be highly appreciated!
Thanks Joanne

--
Joanne Demmler Ph.D.
Research Assistant
College of Medicine
Swansea University
Singleton Park
Swansea SA2 8PP
UK
tel:+44 (0)1792 295674
fax:+44 (0)1792 513430
email:  j.demm...@swansea.ac.uk
DECIPHer:   www.decipher.uk.net

__
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] random sampling or random replacement

2009-06-25 Thread Joanne Demmler

Dear R users,

I'm trying to randomly recreate a real dataset with missing data and I'm 
not quite sure if I can use the sample command for this. I think it 
might be better to do it in 2 steps and randomly replace the sampled 
data with missing data...


So something like this

x - sample(1:2, 100) #without replacement

Now I want x to contain to 20% missing data (NA). Could anyone help me 
how to do this?


Thanks
Joanne

--


Joanne Demmler Ph.D.
Research Assistant
School of Medicine
Swansea University
Singleton Park
Swansea SA2 8PP
UK  


tel:+44 (0)1792 295674
fax:+44 (0)1792 513430
email:  j.demm...@swansea.ac.uk
DECIPHer:   www.decipher.uk.net

__
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] several postscript problems

2008-10-03 Thread Joanne Demmler

Hello everyone,

I'm currently trying to export a couple of graphs to pdf . Postscript 
would be fine too, but I'm using odd page dimensions, which seem to be 
overwritten when using the ps2pdf command. I'm using the pdfpages 
package in LaTeX to put 6 graphs onto one page (this is why it ought to 
be a pdf in the end).


I have two problems:

1. I'm using arrows to add error bars to the plots and they come out 
all misplaced. I've read in older posts that this might be solved using 
Acrobat Reader, but would this mean that I have to teach LaTeX (Lyx) 
somehow to use Acrobat too?


2. I'm also using a legend that includes some dots (pch=1, pch=19), 
which pdf obviously doesn't understand and plots little q symbols 
instead (postscript will understand these symbols). Do I have to load a 
certain font to get it to work?


Joanne


 sessionInfo()
R version 2.7.1 (2008-06-23)
i386-redhat-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

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


Examples:
R:pdf(result.pdf,height=4,width=4)
...
### plot empty window
  plot(0,0, type=n, ylim=c(-180,180), xlim=c(0,0.5), xlab=, 
ylab=Phase, xaxt=n, yaxt=n)

  axis(1,at=seq(0,0.5,0.1),label=rep( ,6))
  axis(2,at=seq(-180,180,90))
  abline(h=0,lty=3)
  legend(topright,c(annual means, summer means),pch=c(19,1),cex=1)

### plot with error bars in loop
plot(get(site[j,i])[k,1],get(site[j,i])[k,3],pch=19,axes=F,ann=F,ylim=c(-180,180),xlim=c(0,0.5),col=plotcolour[i])
arrows(get(site[j,i])[k,1],get(site[j,i])[k,3]+get(site[j,i])[k,4],get(site[j,i])[k,1],get(site[j,i])[k,3]-get(site[j,i])[k,4],length 
= .03, angle = 90, code = 3,col=plotcolour[i])

...
dev.off()

LaTeX:   
\includepdf[pages={1-6},pagecommand={\thispagestyle{fancy}\begin{figure}[!b]\caption{test}\end{figure}},nup=2x3,scale=0.75,offset={0.5cm 
1cm}]{result.pdf}


__
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] several postscript problems

2008-10-03 Thread Joanne Demmler

Thanks,

I upgraded to R 2.7.2 and installed Acrobat Reader. Once Acrobat reader 
is set as default application for pdf  it will automatically also be 
used under Lyx. This solved most problems, but all error bars at pch=1 
dots still look like a little mouse nibbled on them. Perhaps I'll just 
have to change the pch type?


Joanne


P.S.: I only gave the examples to show how I called pdf, plots and 
arrows. The whole script is about 2 pages long and depends on 468 items 
in the workspace.


__
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 rpm for Mandriva 2008.1 ?

2008-09-13 Thread Joanne Demmler
Are there any R rpm's for Mandriva 2008.1? I found a couple of dodgy 
ones that wouldn't install so far (rpmfind.net).


(Sorry that seems so far the only Linux distribution that recognizes my 
hardware on my new laptop correctly. I'm more familiar to Fedora and 
Suse so perhaps I'm just doing something wrong?)


Joanne

__
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 rpm for Mandriva 2008.1 ?

2008-09-13 Thread Joanne Demmler
Found it, but there seems to be a dependency clash. Over the command 
line I get an error mentioning, that some packages are older than the 
ones installed and over the manager I simply get a message can't 
install package.


Joanne

__
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] sink file type and Latex (Lyx)

2008-09-12 Thread Joanne Demmler
Does anyone know what file type sink is outputting to? I've been 
reverting output from R using sink and wanted to add it to my Appendix 
in LaTex (Lyx) using Verbatiminput. However, I get an error message as 
LaTex is expecting an ASCII file.


Can I set sink somehow to ASCII or is there another option?

Thanks  Joanne

__
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] sink file type and Latex (Lyx)

2008-09-12 Thread Joanne Demmler

Thanks very much! options(useFancyQuotes=FALSE) did the trick!

Joanne

P.S.: For reference I'm running R on Linux Fedora 8:

 Sys.getlocale()
[1] 
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

 sessionInfo()
R version 2.7.1 (2008-06-23)
i386-redhat-linux-gnu
locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C
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.