6주

From Biocourse

Jump to: navigation, search
 sort() 를 프로그램 하기 : 반복이 없을때

##sort
> a.sort = aa = a = sample(1:20,20)                                           ## 1부터 20가지 랜덤하게 추출한다.
> for(i in 1:length(a)){                                                                 ## 가장 작은 값을 찾아서 정렬
  a.sort[i]=min(a)   
  a[a==min(a)]=Inf   
 }
> sort(aa)                                                                                     ## sort 함수를 사용하여 결과 유도
[1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20

> a.sort                                                                                        ## 위에서 작업한 결과
[1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20

> paste("Sort ", a.sort)                                                              ## "Sort"와 값을 결합
 [1] "Sort  1"  "Sort  2"  "Sort  3"  "Sort  4"  "Sort  5"  "Sort  6"  "Sort  7"  "Sort  8"  "Sort  9"  "Sort  10"
[11] "Sort  11" "Sort  12" "Sort  13" "Sort  14" "Sort  15" "Sort  16" "Sort  17" "Sort  18" "Sort  19" "Sort  20"


 sort() 를 프로그램 하기 : 반복이 있을때

> a.sort=aa=a=sample(1:20,20,rep=T)                                         ## 반복을 허용하여 랜덤하게 추출한다.
> i=1                                                                                              ## i 에 1을 저장
> while(i <= length(a) ){                                                                 ## 가장 작은 값을 찾아서 정렬
  sum.a = sum(a==min(a))-1   
  a.sort[i:(i+sum.a)] = min(a)   
  a[a==min(a)] = Inf   
  i = i+1+sum.a    
 }
> sort(aa)                                                                                     ## sort 함수를 사용하여 결과 유도
[1]  1  1  2  3  3  4  5  6  7  8  9  9 13 14 15 16 16 17 19 20

> a.sort                                                                                        ## 위에서 작업한 결과
[1]  1  1  2  3  3  4  5  6  7  8  9  9 13 14 15 16 16 17 19 20

> paste("Sort ", a.sort)                                                                 ## "Sort"와 값을 결합
 [1] "Sort  1"  "Sort  1"  "Sort  2"  "Sort  3"  "Sort  3"  "Sort  4"  "Sort  5"  "Sort  6"  "Sort  7"  "Sort  8"
[11] "Sort  9"  "Sort  9"  "Sort  13" "Sort  14" "Sort  15" "Sort  16" "Sort  16" "Sort  17" "Sort  19" "Sort  20"


order() 를 프로그램 하기 : 반복이 없을때

> a.order=aa=a=sample(1:20,20)                                                   ## 1부터 20가지 랜덤하게 추출한다.
> b=1:length(a)                                                                                ## b에 1부터 20까지의 자리를 만든다.
> for(i in 1:length(a)){                                                                       ## 가장 작은 값의 위치를 찾아서 정렬
  a.order[i]=b[a==min(a)]   
  a[a==min(a)]=Inf   
}
> order(aa)                                                                                      ## order 함수를 사용하여 결과 유도
[1] 20 19  8  5 17 10  7  4  1 18 11 15  3 14 12  9  2 13  6 16

> a.order                                                                                         ## 위에서 작업한 결과
[1] 20 19  8  5 17 10  7  4  1 18 11 15  3 14 12  9  2 13  6 16

> paste("locate", a.order)                                                                ## "locate"와 값을 결합
 [1] "locate 20" "locate 19" "locate 8"  "locate 5"  "locate 17" "locate 10" "locate 7"  "locate 4"  "locate 1"  "locate 18"
[11] "locate 11" "locate 15" "locate 3"  "locate 14" "locate 12" "locate 9"  "locate 2"  "locate 13" "locate 6"  "locate 16"


order() 를 프로그램 하기 : 반복이 있을때

> a.order=aa=a=sample(1:20,20,rep=T)                                            ## 1부터 20가지 반복 허용 랜덤하게 추출한다.
> b=1:length(a);i=1                                                                             ## b에 1부터 20까지의 자리를 만든다.
> while(i <= length(a)){                                                                       ## 가장 작은 값의 위치를 찾아서 정렬
  sum.a=sum(a==min(a))-1  
  a.order[i:(i+sum.a)]=b[a==min(a)]  
  a[a==min(a)]=Inf   
  i=i+sum.a+1
 }
> order(aa)                                                                                          ## order 함수를 사용하여 결과 유도
[1]  3  5 19  1 13 11  4 15 14 16  7 18 17  6  2 20 10 12  8  9

> a.order                                                                                             ## 위에서 작업한 결과
[1]  3  5 19  1 13 11  4 15 14 16  7 18 17  6  2 20 10 12  8  9

> paste("locate:", a.order)                                                                  ## "locate"와 값을 결합
 
 [1] "locate: 1"  "locate: 1"  "locate: 2"  "locate: 3"  "locate: 3"  "locate: 4"  "locate: 5"  "locate: 6"  "locate: 7"  "locate: 8"
[11] "locate: 9"  "locate: 9"  "locate: 13" "locate: 14" "locate: 15" "locate: 16" "locate: 16" "locate: 17" "locate: 19" "locate: 20"



1. Read => homework-2week.txt  



****  Gene
별로 Missing처리. => Imputation   ****
1.

 
1) Gene
평균 계산.(전체가 missing 경우는 0)  : R-6-1 Solution
2.
 
2) Missing
확인 : R-6-2 Solution
3.
 
3) Missing
값에 gene 평균으로 대치.  : R-6-3 Solution


          => Gene
평균 계산.


4) Order
function으로 만들어 impute 자료를 Gene 평균값순서로 정렬.

: R-6-4 Solution

          => Excel file
저장.