## R Programming Homework Solution on Gehan Test

• 17th Jun, 2022
• 15:42 PM
```m=list(18,'<10> n=list(30,44,23,'<16> i=0
if((length(m)<10>   print('111')
while (i<2>       m1=sample(m,replace=FALSE)
n1=sample(m,replace=FALSE)
hi=c()
n1=length(m)
n2=length(n)
N=n1+n2
for (i in 1:N){if(i<11 hi[i]=0}else{hi[i]>       delta1=c()
d1=c()
e1=c()
T=0
count1=1
for (i in 1:n1){
if(typeof(m[[count1]])=="character"){
delta1[i]=0
count1=count1+1
T=T+1
}else{
delta1[i]=1
count1=count1+1
}
}
count1=1
for (i in (n1+1):N){
if(typeof(n[[count1]])=="character"){
delta1[i]=0
count1=count1+1
T=T+1
}else{
delta1[i]=1
count1=count1+1
}
}

for (i in 1:n1){
if(typeof(m[[i]])=="character"){
m[[i]]=as.double(substr(m[[i]],2,3))

}
}
for (i in 1:n2){
if(typeof(n[[i]])=="character"){
n[[i]]=as.double(substr(n[[i]],2,3))

}
}
combined_mn =list()
for (j in 1:N){
if(j<(n1+1)){
combined_mn[[j]]=m[[j]]
}
else{
combined_mn[[j]]=n[[j-n1]]
}
}

combined_mn=c(combined_mn)
li=order(unlist(combined_mn))
i=1
data2=c()
h=c()
delta=c()

# Data  1st column in table, h second column
for (i in 1:N){
data2[[i]]=combined_mn[[li[i]]]
h[i]=hi[li[i]]
delta[i]=delta1[li[i]]
}

d1=c()
e1=c()
# d 4th column, e 5th column in table
if(delta1[[1]]==1){
d1[1]=1
e1[1]=0
} else{
d1[1]=0
e1[1]=1
}
i=1
for (i in 2:N){
if(delta[i]==1){d1[i]=d1[i-1]+1}else {d1[i]=d1[i-1]}

}
for (i in 2:N){
if(delta[i]==0){e1[i]=e1[i-1]+1}else {e1[i]=e1[i-1]}

}

R=c()

# Ri 6th column

for (i in 1:N){
if(delta[i]==1){
R[i] =  d1[i] +(T+e1[i])/2
} else {
R[i] = (T+1+d1[i])/2
}
}

#aRi 7th column
aRi=c()
N=length(R)
for (i in 1:N){
aRi[i] = (2*R[i])-N-1
}
data11=c()
for(i in 1:N){
data11[i] = data2[[i]]
}
table <- data.frame(
Data=data11,
hi = h,
deltai = delta,
di = d1,
ei=e1,
Ri=R,
aRi=aRi,
stringsAsFactors = FALSE
)
l1=length(m)
l2=length(n)
p= l1*l2
s=0
t=0
for (i in 1:N){
t=t+(h[i]*aRi[i])
s=s+(aRi[i])^2}

denom = sqrt((p*s)/(N*(N-1)))
num = t
G=num/denom
print(G)
i=i+1
}
}

```