s-news
[Top] [All Lists]

Re: substring()'s problem

To: s-news@lists.biostat.wustl.edu
Subject: Re: substring()'s problem
From: Nora Muda <noramuda@yahoo.com>
Date: Wed, 24 Jan 2007 01:40:15 -0800 (PST)
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Message-ID; b=gfah4oDMK+A/nSKYClw+K8f3HwYcy576s811sEA32zdy/2W/aCKo0fe6tKzxmvFa7oYQ4ka54ix7HYtWK6eaUrj1H9eQtCFaUBi24EfaBFj2vpMI5l+Ek8N2bI+jXxEkGgsuUynzV8B+ZZ9b9bMoQqq1a3cOhIms9Pk7UiGxdiY=;
Thank you Romain and Steffen for your answered. Actually I know if defined as first, second and third character. But I want it  become first and second character only; 1 and 10.
 
below are my programs that the last output should be like the blue one:

n <- 10

label <- array(dim=n,NA)

for(i in 1:n) label[i] <- i

small <- 3

big <- 4

label[small] <- as.numeric(paste(label[small],label[big],sep=""))

labelSmall <- label[small]

label[big] <- NA

lengLabel <- array(dim=n-1,NA)

cell <- array(dim=nchar(labelSmall),NA)

for(j in 1:nchar(labelSmall)){

cell[j] <- as.numeric(substring(labelSmall,j,j))

}

for(i in 1:n){

if(i!=small && i!=big ){

labelOther <- label[i]

lengOther <- nchar(labelOther)

index <- array(dim=length(lengOther),NA)

weight <- length(lengOther)*length(cell)

d <- matrix(NA,length(cell),length(lengOther))

for(j in 1:length(cell)){

for(k in 1:length(lengOther)){

index[k] <- as.numeric(substring(labelOther,k,k))

d[j,k] <- as.numeric(paste(index[k],cell[j],sep=""))

}

}

print(d)

}

}

outputs:

[,1]

[1,] 13

[2,] 14

[,1]

[1,] 23

[2,] 24

[,1]

[1,] 53

[2,] 54

[,1]

[1,] 63

[2,] 64

[,1]

[1,] 73

[2,] 74

[,1]

[1,] 83

[2,] 84

[,1]

[1,] 93

[2,] 94

[,1]

[1,] 13        --------->    [1,] 103

[2,] 14                            [2,] 104

 

The outputs will be used in future clustering process where any number can be clustered together following the rule given; let say after this "110" joined with number 8, so it can be "1810". I want it become first, second and third character only, here '0' not a fourth character.

 

Is there any way to modified it?

 

 

 

--Nora .



Don't get soaked. Take a quick peak at the forecast
with theYahoo! Search weather shortcut.
<Prev in Thread] Current Thread [Next in Thread>
  • Re: substring()'s problem, Nora Muda <=