[S] library maps on Windows

srosenfeld@nesdis.noaa.gov
Fri, 17 Apr 98 15:11:39 -0500


Dear S'ers:
Many thanks to all folks who helped me to solve the problem:

> Can anybody help me in solving the following problem:
> I have a series of complex numbers z[i], i=1,....,N
> There are numerous repetitions in these numbers. For example, N is of order
> 1,000,000. However, only ~20,000 of z[i] are different. I need to assign a
> unique name or number to each of z[i] in such a way that equal z have the same
> name.
> For example, I have
>
> z_c(0+0i,1+0i,0+1i,1+1i,10+1i,0+1i,0+1i,1+1i,10-1i,0+1i,10+1i,0+1i,0+1i,1+1i)
>
> I need to name them as follows
>
names(z)_c("z1","z2","z3","z4","z5","z3","z3","z4","z6","z3","z5","z3","z3","z4"
> )

Here is the summury of answers:

11111111:

Here's a one-liner which uses the very powerful, but often overlooked,
match function:

names(z)<-paste("z",match(z,unique(z)),sep="")

Shawn Boles, Ph.D.

Oregon Research Institute Internet: shawn@ori.org
1715 Franklin Blvd. Voice: (541) 484-2123 Ext. 225
Eugene, Oregon /97403-1983 USA Fax: (541) 484-1108

222222222:
Try this:

names( z ) <- paste( "z", match( z, unique( z )), sep = "" )

or if you just want a unique number:

uniquenums <- match( z, unique( z ))

--Jennifer Hodgdon
_______________________________________________
Jennifer Hodgdon jhodgdon@statsci.com
(206)283-8802 x297 Fax (206)283-8691
MathSoft, Inc., 1700 Westlake Ave N, Seattle, WA 98109

3333333:

z _ complex(real=sample(1:10, replace=T,
size=100),imaginary=sample(1:10,replace=T, size=100))

Now
z.f <- factor(z)

as.numeric(z.f)

gives the numeric decription,

levels(z.f)

gives the mapping of numbers to labs.

S.D.Byers" <byers@stat.washington.edu>

4444444:
There are probably many variations on this theme, but try
something along the lines of:

unique.values <- unique(z)
unique.names <- paste("z", 1:length(unique.values), sep="")
all.names <- unique.names(match(z, unique.values))
names(z) <- all.names

Hope that helps.

--Todd

-- 
Z. Todd Taylor
Pacific Northwest National Laboratory
Todd.Taylor@pnl.gov
Why is it Filipino, not Philippino?

5555555:

One way to do this is to use the "factor" function, then change the names using the "levels" function.

zfac <- factor(z) levels(z) <- c("z1","z2","z3", ...)

I hope this helps,

Rod

------------------ Rod Tjoelker Applied Statistics The Boeing Company

777777777:

There is a meta-answer to many of the questions proposed on this list and that is "use the match function and indexing".

Here is how it would work in this case:

Try the following:

name(z) <- paste('z',match(z,unique(z)),sep='')

888888888:

x_factor(z)

is all you need to do. The levels of the factor are by default the character representations of the values in z and are coded by 1,2, ... length(unique(z)). codes(x) will give you all the (repeated) codes. You can use the labels option of factor if you would like "labels" for the numbers different than 1,2, ...length(unique(z)).

Bert Gunter Biometrics Research Merck Research Labs P.O. Box 2000 Rahway, NJ 07065-0900 732-594-7765

999999999: A quick and easy way to identify identical elements of a vector is the function match():

Try

z_c <- complex(real = round(rnorm(1000),1), imaginary = round(rnorm(1000),1)) names(z_c) <- paste("z", match(z_c,z_c), sep="")

For 1'000'000 elements this only takes a couple of seconds on a 200 MHz Pentium Pro PC (NT4.0, S+4.0)

Greetings

Jan

--------------------------------------------------------------- Jan Schelling Institute of Process Engineering ETH Zurich, 8092 Switzerland phone: ++41-1-633 62 63 fax: ++41-1-633 11 19 email: schelling@ivuk.mavt.ethz.ch internet: http://www.ivuk.ethz.ch/staff/Schelling/

##################

Thanks again,

Simon Rosenfeld NOAA Science Center, NESDIS/Satellite Research Lab Camp Springs, MD ----------------------------------------------------------------------- This message was distributed by s-news@wubios.wustl.edu. To unsubscribe send e-mail to s-news-request@wubios.wustl.edu with the BODY of the message: unsubscribe s-news