|
This might help you
> lab <- c(1:9, 0, LETTERS)
> length(lab)
[1] 36
> print(lab, quote = F)
[1] 1 2 3 4 5 6 7 8 9 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
> x <- sample(36, size = 100, replace = T)
> x
[1] 34 17 6 2 14 16 15 4 10 7 31 27 3 13 30 2 7 21 15 21 30 26 2 26 36 29 34
[28] 11 13 35 32 28 10 15 12 2 9 11 18 36 11 32 23 30 2 24 7 9 27 16 20 28 14 26
[55] 6 8 19 18 35 16 31 24 23 3 36 35 9 12 2 1 16 15 13 27 8 7 18 5 21 24 23
[82] 30 28 28 23 28 1 22 3 34 31 4 7 14 27 7 34 36 32 4
> lab[x]
[1] "X" "G" "6" "2" "D" "F" "E" "4" "0" "7" "U" "Q" "3" "C" "T" "2" "7" "K" "E" "K"
[21] "T" "P" "2" "P" "Z" "S" "X" "A" "C" "Y" "V" "R" "0" "E" "B" "2" "9" "A" "H" "Z"
[41] "A" "V" "M" "T" "2" "N" "7" "9" "Q" "F" "J" "R" "D" "P" "6" "8" "I" "H" "Y" "F"
[61] "U" "N" "M" "3" "Z" "Y" "9" "B" "2" "1" "F" "E" "C" "Q" "8" "7" "H" "5" "K" "N"
[81] "M" "T" "R" "R" "M" "R" "1" "L" "3" "X" "U" "4" "7" "D" "Q" "7" "X" "Z" "V" "4"
> y <- xზ
> y <- ifelse(y > 36, y - 36, y)
> xy <- paste(lab[x], lab[y], sep = "")
> print(xy, quote = F)
[1] X8 GQ 6F 2B DN FP EO 4D 0J 7G U5 Q1 3C CM T4 2B 7G KU EO KU T4 PZ 2B PZ Z0 S3 X8
[28] AK CM Y9 V6 R2 0J EO BL 2B 9I AK HR Z0 AK V6 MW T4 2B NX 7G 9I Q1 FP JT R2 DN PZ
[55] 6F 8H IS HR Y9 FP U5 NX MW 3C Z0 Y9 9I BL 2B 1A FP EO CM Q1 8H 7G HR 5E KU NX MW
[82] T4 R2 R2 MW R2 1A LV 3C X8 U5 4D 7G DN Q1 7G X8 Z0 V6 4D
> X <- match(substring(xy, 1, 1), lab)
> Y <- match(substring(xy, 2, 2), lab)
> x-X
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[42] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[83] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> y-Y
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[42] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[83] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>
Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): ᄉ 7 3826 7251
Fax (if absolutely necessary): ᄉ 7 3826 7304
Mobile: (I don't have one!)
Home Phone: ᄉ 7 3286 7700
mailto:Bill.Venables@csiro.au
http://www.cmis.csiro.au/bill.venables/
_____________________________________________
From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Nora Muda
Sent: Monday, 5 February 2007 7:09 PM
To: s-news@lists.biostat.wustl.edu
Subject: [S] convert numeric to character
Dear S-Plus users,
I want to change the 2 digits number become character.
For example:
n <- 36
label <- array(dim=n, NA)
for(i in 1:n) label[i] <- i
here I want ;
label[10] become 0, and label[11] = A, label[12] = B, .. etc
eq. output:
label: [1] [2] [ 3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18]
1 2 3 4 5 6 7 8 9 0 A B C D E F G H
[19][20][21][22][23][24] [25][25][27][28] [29][30][31][32] [33][ 34][35][36]
I J K L M N O P Q R S T U V W X Y Z
label[11]= A; A=11
Is it possible? If yes, how can I convert it to character?
Thank you for any suggestions.
Nora.
________________________________
Don't be flakey. Get Yahoo! Mail for Mobile <http://us.rd.yahoo.com/evt=43909/*http://mobile.yahoo.com/mail> and
always stay connected <http://us.rd.yahoo.com/evt=43909/*http://mobile.yahoo.com/mail> to friends.
|