>

R에서 수행하는 분석의 결과 인 output.txt 파일이 있습니다. 추출하고 싶습니다 :

  • 와이즈 비즈  각 주제에 대한 .txt 파일의 테이블을 R 데이터 프레임으로 결합합니다. 출력 항목 이름은 각 주제마다 일치합니다.
  • 와이즈 위즈도 마찬가지  R의 데이터 프레임으로 결합하십시오.

알다시피, 출력 파일은 필요없는 사이에 텍스트를 썼습니다.

output.txt 파일의 구조를 쉽게 볼 수 있도록 다음 링크 여기 . 또한 출력이 어떻게 구성되어 있는지 보여주기 위해 아래 스크린 샷을 넣습니다.

다음과 같은 것을 사용하여이 작업을 시도했지만 운이 없습니다 :

<< Output >>

<< Predicted Output >>

  • 답변 # 1

    시작해보십시오. 필요한 경우 더 많은 조건을 추가하십시오. 도움이 되길 바랍니다. 궁금한 점이 있으면 언제든지 문의하십시오.

    b = readLines(file('ivivc_outputs.txt', 'r'))
    n_out = 1
    n_pred = 1
    listOutput = list()
    listPredictOutput = list()   
    for(i in 1:length(b)){
        if(b[i] == "<< Output >>"){
            a = strsplit(b[i+1], " ")[[1]]
            a = a[a != ""]
            #         print(a)
            df <- data.frame(matrix(ncol = length(a), nrow = 0))
            colnames(df) = a       
            control = 2
            while(control != 20){
                l = strsplit(b[i+control], " ")[[1]]
                l = l[l != ""]
                df[control-1,] = l
                control = control + 1 
            }
            listOutput[[n_out]] = df
            n_out = n_out+1
        }
        if(b[i] == "<< Predicted Output >>"){
            a = strsplit(b[i+1], " ")[[1]]
            a = a[a != ""]
            #         print(a)
            df <- data.frame(matrix(ncol = length(a), nrow = 0))
            colnames(df) = a       
            control = 2
            while(control != 20){
                l = strsplit(b[i+control], " ")[[1]]
                l = l[l != ""]
                df[control-1,] = l
                control = control + 1 
            }
            listPredictOutput[[n_pred]] = df
            n_pred = n_pred+1
        }
    }
    
    
    # to merge all data frames use `bind_rows` from `dplyr`
    library(dplyr)
    dfOutput = bind_rows(listOutput)
    dfPredictOutput = bind_rows(listPredictOutput)
    
      >   dfPredictOutput
        #      pH subj       formula. time    FABpred conc.pred     AUCpred
        # 1   1.2    1        capsule  0.0   0.000000   0.00000     0.00000
        # 2   1.2    1        capsule  1.0   2.528737   8.39300     4.19650
        # 3   1.2    1        capsule  2.0   7.415708  22.57987    19.68293
        # 4   1.2    1        capsule  3.0  15.845734  45.08950    53.51761
        # 5   1.2    1        capsule  4.0  24.275759  62.14611   107.13542
        # 6   1.2    1        capsule  5.0  33.133394  76.48998   176.45346
        # 7   1.2    1        capsule  6.0  41.991029  87.35901   258.37796
        # 8   1.2    1        capsule  6.5  45.900606  89.90799   302.69471
        # 9   1.2    1        capsule  7.0  49.810183  92.12832   348.20378
        # 10  1.2    1        capsule  7.5  53.719760  94.06237   394.75146
        # 11  1.2    1        capsule  8.0  57.629337  95.74705   442.20381
        # 12  1.2    1        capsule  8.0  57.629337  95.74705   442.20381
        # 13  1.2    1        capsule  9.0  63.860225  93.23271   536.69369
        # 14  1.2    1        capsule 10.0  70.091113  91.32747   628.97378
        # 15  1.2    1        capsule 12.0  79.498532  79.70975   800.01101
        # 16  1.2    1        capsule 16.0  90.372043  49.52751  1058.48553
        # 17  1.2    1        capsule 20.0 101.245554  40.79704  1239.13462
        # 18  1.2    1        capsule 24.0 107.354268  26.67212  1374.07293
        # 19  1.2    1 capsuleContent  0.0   0.000000  0.000000    0.000000
        # 20  1.2    1 capsuleContent  1.0   1.490256  4.946231    2.473115
        # 21  1.2    1 capsuleContent  2.0   5.338746 16.521316   13.206889
        # 22  1.2    1 capsuleContent  3.0  13.341161 39.079386   41.007240
        # 23  1.2    1 capsuleContent  4.0  21.343576 56.172708   88.633287
        # 24  1.2    1 capsuleContent  5.0  30.017950 71.355393  152.397337
        # 25  1.2    1 capsuleContent  6.0  38.692324 82.860036  229.505052
        # 26  1.2    1 capsuleContent  6.5  42.571357 85.881180  271.690356
        # 27  1.2    1 capsuleContent  7.0  46.450390 88.512793  315.288850
        # 28  1.2    1 capsuleContent  7.5  50.329423 90.805099  360.118323
        # 29  1.2    1 capsuleContent  8.0  54.208457 92.801847  406.020060
        # 30  1.2    1 capsuleContent  8.0  54.208457 92.801847  406.020060
        # 31  1.2    1 capsuleContent  9.0  60.439345 91.000989  497.921478
        # 32  1.2    1 capsuleContent 10.0  66.670233 89.636393  588.240168
        # 33  1.2    1 capsuleContent 12.0  76.322001 79.472871  757.349432
        # 34  1.2    1 capsuleContent 16.0  87.256599 49.607701 1015.510577
        # 35  1.2    1 capsuleContent 20.0  98.191197 40.968947 1196.663873
        # 36  1.2    1 capsuleContent 24.0 104.177736 26.424419 1331.450604
        # 37  1.2    2        capsule  0.0   0.000000   0.00000     0.00000
        # 38  1.2    2        capsule  1.0   2.528737   8.39300     4.19650
        # 39  1.2    2        capsule  2.0   7.415708  22.57987    19.68293
        # 40  1.2    2        capsule  3.0  15.845734  45.08950    53.51761
        # 41  1.2    2        capsule  4.0  24.275759  62.14611   107.13542
        # 42  1.2    2        capsule  5.0  33.133394  76.48998   176.45346
        # 43  1.2    2        capsule  6.0  41.991029  87.35901   258.37796
        # 44  1.2    2        capsule  6.5  45.900606  89.90799   302.69471
        # 45  1.2    2        capsule  7.0  49.810183  92.12832   348.20378
        # 46  1.2    2        capsule  7.5  53.719760  94.06237   394.75146
        # 47  1.2    2        capsule  8.0  57.629337  95.74705   442.20381
        # 48  1.2    2        capsule  8.0  57.629337  95.74705   442.20381
        # 49  1.2    2        capsule  9.0  63.860225  93.23271   536.69369
        # 50  1.2    2        capsule 10.0  70.091113  91.32747   628.97378
        # 51  1.2    2        capsule 12.0  79.498532  79.70975   800.01101
        # 52  1.2    2        capsule 16.0  90.372043  49.52751  1058.48553
        # 53  1.2    2        capsule 20.0 101.245554  40.79704  1239.13462
        # 54  1.2    2        capsule 24.0 107.354268  26.67212  1374.07293
        # 55  1.2    2 capsuleContent  0.0   0.000000  0.000000    0.000000
        # 56  1.2    2 capsuleContent  1.0   1.490256  4.946231    2.473115
        # 57  1.2    2 capsuleContent  2.0   5.338746 16.521316   13.206889
        # 58  1.2    2 capsuleContent  3.0  13.341161 39.079386   41.007240
        # 59  1.2    2 capsuleContent  4.0  21.343576 56.172708   88.633287
        # 60  1.2    2 capsuleContent  5.0  30.017950 71.355393  152.397337
        # 61  1.2    2 capsuleContent  6.0  38.692324 82.860036  229.505052
        # 62  1.2    2 capsuleContent  6.5  42.571357 85.881180  271.690356
        # 63  1.2    2 capsuleContent  7.0  46.450390 88.512793  315.288850
        # 64  1.2    2 capsuleContent  7.5  50.329423 90.805099  360.118323
        # 65  1.2    2 capsuleContent  8.0  54.208457 92.801847  406.020060
        # 66  1.2    2 capsuleContent  8.0  54.208457 92.801847  406.020060
        # 67  1.2    2 capsuleContent  9.0  60.439345 91.000989  497.921478
        # 68  1.2    2 capsuleContent 10.0  66.670233 89.636393  588.240168
        # 69  1.2    2 capsuleContent 12.0  76.322001 79.472871  757.349432
        # 70  1.2    2 capsuleContent 16.0  87.256599 49.607701 1015.510577
        # 71  1.2    2 capsuleContent 20.0  98.191197 40.968947 1196.663873
        # 72  1.2    2 capsuleContent 24.0 104.177736 26.424419 1331.450604
        # 73  1.2    3        capsule  0.0   0.000000   0.00000     0.00000
        # 74  1.2    3        capsule  1.0   2.528737   8.39300     4.19650
        # 75  1.2    3        capsule  2.0   7.415708  22.57987    19.68293
        # 76  1.2    3        capsule  3.0  15.845734  45.08950    53.51761
        # 77  1.2    3        capsule  4.0  24.275759  62.14611   107.13542
        # 78  1.2    3        capsule  5.0  33.133394  76.48998   176.45346
        # 79  1.2    3        capsule  6.0  41.991029  87.35901   258.37796
        # 80  1.2    3        capsule  6.5  45.900606  89.90799   302.69471
        # 81  1.2    3        capsule  7.0  49.810183  92.12832   348.20378
        # 82  1.2    3        capsule  7.5  53.719760  94.06237   394.75146
        # 83  1.2    3        capsule  8.0  57.629337  95.74705   442.20381
        # 84  1.2    3        capsule  8.0  57.629337  95.74705   442.20381
        # 85  1.2    3        capsule  9.0  63.860225  93.23271   536.69369
        # 86  1.2    3        capsule 10.0  70.091113  91.32747   628.97378
        # 87  1.2    3        capsule 12.0  79.498532  79.70975   800.01101
        # 88  1.2    3        capsule 16.0  90.372043  49.52751  1058.48553
        # 89  1.2    3        capsule 20.0 101.245554  40.79704  1239.13462
        # 90  1.2    3        capsule 24.0 107.354268  26.67212  1374.07293
        # 91  1.2    3 capsuleContent  0.0   0.000000  0.000000    0.000000
        # 92  1.2    3 capsuleContent  1.0   1.490256  4.946231    2.473115
        # 93  1.2    3 capsuleContent  2.0   5.338746 16.521316   13.206889
        # 94  1.2    3 capsuleContent  3.0  13.341161 39.079386   41.007240
        # 95  1.2    3 capsuleContent  4.0  21.343576 56.172708   88.633287
        # 96  1.2    3 capsuleContent  5.0  30.017950 71.355393  152.397337
        # 97  1.2    3 capsuleContent  6.0  38.692324 82.860036  229.505052
        # 98  1.2    3 capsuleContent  6.5  42.571357 85.881180  271.690356
        # 99  1.2    3 capsuleContent  7.0  46.450390 88.512793  315.288850
        # 100 1.2    3 capsuleContent  7.5  50.329423 90.805099  360.118323
        # 101 1.2    3 capsuleContent  8.0  54.208457 92.801847  406.020060
        # 102 1.2    3 capsuleContent  8.0  54.208457 92.801847  406.020060
        # 103 1.2    3 capsuleContent  9.0  60.439345 91.000989  497.921478
        # 104 1.2    3 capsuleContent 10.0  66.670233 89.636393  588.240168
        # 105 1.2    3 capsuleContent 12.0  76.322001 79.472871  757.349432
        # 106 1.2    3 capsuleContent 16.0  87.256599 49.607701 1015.510577
        # 107 1.2    3 capsuleContent 20.0  98.191197 40.968947 1196.663873
        # 108 1.2    3 capsuleContent 24.0 104.177736 26.424419 1331.450604
    
    

  • 이전 html - 왜 배경 그림 위에 홈페이지에서 패널을 볼 수 없습니까?
  • 다음 mysql - 단일 열 구조로 데이터가 저장된 테이블에서 다중 필터 쿼리