Showing posts with label R. Show all posts
Showing posts with label R. Show all posts

How to reconfigure a keyboard

at 15 November 2007

Recently we held an the introductory R-course. In R you need to use the tilde (~) sign often. Everytime you specify a statistical formula, you write something like:



Y ~ Treatment + X



One of the participants had a keyboard on her (italian) laptop that had no '~' sign. As one of the participants could remember, that is no problem. You simply type the ASCII-code of '~' (126) on the numeric keypad while you hold down the 'Alt' key. And of course, on a laptop without a numeric keyboard you simply find the blue 'fn' key and the blue 'num lock' key and push them down simultaneously, then you type the ASCII code with the Alt key pressed, and then the blue 'fn' key and the blue 'num lock' key again. (If you forget the final part, 5t 5s act4a33y n4 *r6b3e0, s60e 6f the 2eys are s50*3y re*3aced w5th n40bers, oops - I meant to say, it is actually no problem, some of the keys are simply replaced with numbers).


The R-Help list had some discussion concerning this problem in 2004, where the solution above was suggested.

However, the satisfactory solution is to remap the keyboard. Microsoft has a utility program for doing this. You may download it from the Microsoft Keyboard Layout Creator. For Windows XP you probably need the old version (1.3), while Vista users can use version 1.4.


The instructions in the help menu are easy to follow. I'll just show a couple of screen dumps. First of all I load an existing keyboard via the File | Load existing keyboard option. I choose the Danish keyboard. The program then shows an image of the existing keyboard layout.





By selecting the different shift states, you may see the key mapping in the corresponding states. As an example, the AltGr shift state below.





In fact I have already changed the keyboard mapping. As you an see the keyboard now shows a '~' sign corresponding to the 'N' key. In order to obtain this mapping I simply clicked on the key in the screen image. A popup window allowed me to type the '~'-sign and he redefinition was made. (If your keyboard does not have the '~' sign you need to use the trick with the numeric keyboard and Alt 126 as described above).

Finally, you choose Project| Build DLL and setup Package, as described in Help file of the program. This produces an msi-file that can be executed and your new keyboard is installed.



So now I have a keyboard that produces a a tilde sign when I press AltGr+N. In contrast to the existing one (next to the Enter key in the right hand side) this one is not a dead key. I do not need to wait for another keypress to see the '~'sign.


Another option is to use e.g. AutoHotkey.

How to import SAS data set into R

at 07 November 2007

The import of data into R is still a bit complicated if the original data are stored in the SAS-data format. Though solutions have existed for a long time, see e.g. the R-documentation concerning Importing from other statistical systems, it is complicated to use these facilities. They are based on functions which need to call the SAS-program from R. The settings for doing this do not always correspond to the settings on the computers we use.

I have written a short note/web-page with focus on the export problem from the SAS point of view. The note compares three different intermediate formats: csv, xls and xport format.

In normal use, the route via the xls format seems best. Data are exported via SAS code similar to:

 
libname sasdata "C:/SASImport";
libname out Excel
"C:/SASImport/file798b12e1.xls";
data out.rimporttest;
set sasdata.rimporttest;
run;

and imported into R via the read.xls command in the xlsReadWrite package.


Further detail in the note, which also includes R-functions. The note is also available as a pdf-file

R for SAS and SPSS users

at 02 May 2007

I came across this document - RforSAS&SPSSusers.pdf - which gives a nice R-introduction to people familiar with other statistical packages. It might be of use in connection with various courses.

SASweave - writing LaTeX docs and SAS (and R) code together

at 12 January 2007

A looooong time ago I wrote a small package allowing combining LaTeX, SAS and R into one document. I never took the work any further than the first version...

Russ Lenth from Iowa found it on the Web and he has now created a fully functional program called "SASweave" (see the link) - mainly for working with SAS and LaTeX together, but it is also possible to use it additionally with R code. We are currently writing a little paper about the program, so any input/comments/experiences from you will be appreciated. Currently I am using it when preparing the lecture slides etc. for out mixed model course in Spring 2007. It works fairly well - if I may say so...

R packages

at 28 February 2006

I have now installed a R package repository on our webserver.
The main reason was, that I wanted a R repository, such that our courses data package
can be installed straightforwardly using the install.packages funtion.

In the directory on our web server

/usr/home/biomet/public_html/software/r/packages

findes en subdirectory structure
bin > windows> contrib > 2.2
and in the lowest direcotry you find
1) zip filen af den datapackage datRep we use in our courses
2) PACKAGES file, that is just a file containing the contents of the DESCRIPTION file of
the packages in this directory.


You access the directory from the net via:
http://gbi.agrsci.dk/biometry/software/r/packages


It is possible to install the data-package from R by
install.packages("dataRep",repos="http://gbi.agrsci.dk/biometry/software/r/packages")

We need to discuss how we mange the package repository in future.

Whenever a new -zip file is added to the directory, the PACKAGES file has to be updated.

Someone adding a package has to do two steps

a) copy his zip file to
/usr/home/biomet/public_html/software/r/packages/bin/windows/2.2
b) running the function write_PACKAGES of the tools package

write_PACKAGES("/usr/home/biomet/public_html/software/r/packages/bin/windows/2.2")

I think, this functions has to be executed in R on the unix machine.

(At the moment I do everything on my PC and copy everything to the web-sever)



I hope that my initiative was not too premature.


Ulrich

R-Pakke med data-eksempler

at 08 January 2006

Vi har jo ofte behov for at anvende datasæt som eksempler ved undervisning, eller når vi skriver artikler. Det ender ofte med, at data findes frem i sidste øjeblik, og bagefter glemmer vi alt om data. Derfor har jeg påbegyndt en R-pakke til at gemme og beskrive datasæt fra de forsøg, vi er involveret i.

Det er faktisk ganske let. Når data er finpudset gemmer man dem som en rda fil, og kalder funktionen promptData, som generer en template (*.rd fil) for beskrivelsen af datasættet. Denne template tilrettes. *.rda filen placeres i Data directory for pakken og *.rd filen placeres i man directory. Pakken kompileres og komprimeres og er nu klar. Som eksempel et datasæt med cortisol målinger for grise. I R blev der eksekveret:

save(PigCortisol,file="PigCortisol")
promptData(PigCortisol)

og PigCortisol.rd derefter tilrettet og placeret det rigtige sted.

Pakken DIASData med foreløbigt 2 datasæt (grisevækstdata og cortisoldata med døgnvariation til brug ved eksemplificering af random regression) er placeret her, mens hele kildeteksten er her. Førstnævnte fil installeres i R via Packages|Install from local file. Jeg vil senere placere kildeteksten på vores fælles drev (I:) under biometri\RPackages. I opfordres til at bidrage til samlingen.

Tilføjer 9/1: Så er filerne placeret på fællesdrevet