Dear R-friends,
the dataset I am using (data.it) is organized as follows
partner stp btp reg
hk 0.64 1 s
ger 0.27 1 d
tur 0.27 1 s
rom 0.24 1 s-f
por 0.24 1 s
spa 0.23 1 s
gre 0.22 1 d-f
aus 0.17 1 d
uk 0.16 1 s
be 0.16 1 d
arg 0.15 1 s
usa 0.13 1 d-f
fra 0.13 1 s
neth 0.05 1 s-f
pol 0.05 1 d
bra 0.04 1 s
ko 0.006 1 s
un -0.009 2 d-f
svi -0.022 2 s-f
cin -0.040 2 d
ru -0.074 2 d-f
mex -0.077 2 s
... ... ... ...
and plotting it using dotplot, I specified the script as:
library(lattice)
attach(data.ita)
dotplot(reg~stp | partner, data=data.ita, groups=btp,
xlab=list("Data -
it",cex=1.5),col=c("black","red"),aspect=0.3,as.table=TRUE,xlim=c(-1,1))
detach(data.ita)
In the resulting plot the variable "reg" is ordered alphabetically.
Instead, I would like the variable to be plotted in the following order:
"s", "s-f", "d", "d-f".
How can I do it?
Many thanks
Luca
ordering in dotplot
6 messages · Luca De Benedictis, Chuck Cleland, Giampiero Salvi +3 more
Luca De Benedictis wrote:
the dataset I am using (data.it) is organized as follows
... ... ... ...
and plotting it using dotplot, I specified the script as:
library(lattice)
attach(data.ita)
dotplot(reg~stp | partner, data=data.ita, groups=btp,
xlab=list("Data -
it",cex=1.5),col=c("black","red"),aspect=0.3,as.table=TRUE,xlim=c(-1,1))
detach(data.ita)
In the resulting plot the variable "reg" is ordered alphabetically.
Instead, I would like the variable to be plotted in the following order:
"s", "s-f", "d", "d-f".
Make that an ordered factor as follows:
data.it$reg <- ordered(data.it$reg, levels=c("s", "s-f", "d", "d-f"))
hope this helps,
Chuck Cleland
Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894
Hi, I'd like to store N vectors of different lengths, and to be able to access them with an index, and eventually free the memory for one of them without modifying the indexes to the others. In C this would be a vector of N pointers that point to memory cells independently allocated. For example int *pv[3]; pv[0] = (int *) malloc(13 * sizeof(int)); pv[1] = (int *) malloc(7 * sizeof(int)); pv[2] = (int *) malloc(110 * sizeof(int)); free(pv[1]) ... What is the best data type (or class) in R to do such a thing? Thank you! Giampiero _________________________________________________________ Giampiero Salvi, M.Sc. www.speech.kth.se/~giampi Speech, Music and Hearing Tel: +46-8-790 75 62 Royal Institute of Technology Fax: +46-8-790 78 54 Drottning Kristinasv. 31, SE-100 44, Stockholm, Sweden
Giampiero Salvi wrote:
Hi, I'd like to store N vectors of different lengths, and to be able to access them with an index, and eventually free the memory for one of them without modifying the indexes to the others.
int *pv[3]; pv[0] = (int *) malloc(13 * sizeof(int)); pv[1] = (int *) malloc(7 * sizeof(int)); pv[2] = (int *) malloc(110 * sizeof(int)); free(pv[1]) ... What is the best data type (or class) in R to do such a thing?
A list, with vector elements (index starts at 1 in R): pv = list() pv[[1]] = real(13) pv[[2]] = real(7) pv[[3]] = real(110) then the equivalent of freeing the memory and keeping the indexing would be: pv[[2]] = real(0) and NOT pv[[2]] = NULL (which deletes element 2) *BUT* I dont know if R will really free() the memory at that point. You may need to force the garbage collection with gc().... Baz
On Mon, 2 Feb 2004, Giampiero Salvi wrote:
Hi, I'd like to store N vectors of different lengths, and to be able to access them with an index, and eventually free the memory for one of them without modifying the indexes to the others. In C this would be a vector of N pointers that point to memory cells independently allocated. For example int *pv[3]; pv[0] = (int *) malloc(13 * sizeof(int)); pv[1] = (int *) malloc(7 * sizeof(int)); pv[2] = (int *) malloc(110 * sizeof(int)); free(pv[1]) ... What is the best data type (or class) in R to do such a thing?
Sounds like an R list. However, in R you cannot free memory, but what
you can do (carefully) is to change the list element to NULL and then
memory will be salvaged at a future garbage collection.
z <- vector("list", 3)
z[[1]] <- integer(13)
z[[2]] <- integer(7)
z[[3]] <- integer(110)
then
z[1] <- list(NULL) # and not z[[1]] <- NULL
will potentially release the memory allocated for the first element.
Brian D. Ripley, ripley at 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, UK Fax: +44 1865 272595
Giampiero Salvi wrote:
Hi, I'd like to store N vectors of different lengths, and to be able to access them with an index, and eventually free the memory for one of them without modifying the indexes to the others. In C this would be a vector of N pointers that point to memory cells independently allocated. For example int *pv[3]; pv[0] = (int *) malloc(13 * sizeof(int)); pv[1] = (int *) malloc(7 * sizeof(int)); pv[2] = (int *) malloc(110 * sizeof(int)); free(pv[1]) ... What is the best data type (or class) in R to do such a thing?
See ?list Uwe Ligges