Category: R

  • boxplot의 whisker 구하기

    gross 항목의 whisker를 구해보도록 하자. boxplot의 위쪽 whisker는 (Q3-Q1) * 1.5 를 넘어서는 값으로 알려져 있다.

    boxplot.stats() 을 이용하면 구할 수 있다. dataframe이나 list 형식의 자료는 처리할 수 없다. pull()을 이용해서 자료를 추출한다.

    > boxplot.stats(dt %>% filter(Refri == 'gross') %>% pull(Temp))
    $stats
    [1] 5.7 6.2 6.4 6.7 7.4
    
    $n
    [1] 1647
    
    $conf
    [1] 6.380534 6.419466
    
    $out
     [1] 8.9 8.9 8.4 8.4 8.2 7.8 7.6 7.6 7.6 7.6 7.7 7.8 7.8 7.8 8.1 7.8 7.7 7.8 7.8 8.1 7.6 7.8 7.7 7.6 7.9 7.8 7.8 7.7 7.6 7.9 8.1 8.3 7.8 8.2 7.6 7.8 7.7 7.9 7.5 7.7 7.8 7.7 7.6 7.8 7.8
    [46] 8.1 8.2 7.6 7.8 7.6 7.6 8.9 8.2 8.3 7.6 7.9 7.6

    그러면 $out 항목에서 whisker 값을 알 수 있다.

    사용할 때 주의할 점. 이렇게 구한 것은 coef = 1.5가 기본값이다. 통계의 주요 5값을 구하려면 coef = 0을 지정해야 한다.

  • RStudio Server in Docker

    sudo docker rm -f rstudio
    
    sudo docker run -it \
    --name rstudio \
    --restart always \
    --dns 8.8.8.8 \
    -p 8788:8787 \
    --add-host rcc.work:192.168.126.37 \
    debian
    
    echo 'Acquire::http::Proxy "http://rcc.work:3142";' > /etc/apt/apt.conf
    rm -rf /etc/localtime
    ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime 
    apt-get -y update && apt-get -y upgrade
    apt-get -y install dialog gpg wget locales
    
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B8F25A8A73EACF41
    
    gpg --keyserver keyserver.ubuntu.com \
        --recv-key '95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7'
    
    
    
    echo 'deb http://cloud.r-project.org/bin/linux/debian bookworm-cran40/' >> /etc/apt/sources.list
    
    #ttps://debian.pkgs.org/11/debian-main-amd64/libssl1.1_1.1.1w-0+deb11u1_amd64.deb.html
    wget http://ftp.de.debian.org/debian/pool/main/o/openssl/libssl1.1_1.1.1w-0+deb11u1_amd64.deb
  • refresh using shinyjs

    Shiny에서 refresh 기능을 이용해야 할 경우가 있다. 그러니까 F5 키를 누르지 않고도 새로 고침을 해야할 때이다. shinyjs를 사용하는 방법이 있다.

    설치는 다음과 같이 한다.

    install.packages("remotes")
    remotes::install_github("daattali/shinyjs")

    다음에는 ui 부분에서 useShinyjs() 를 적용한다.

    ui <- fluidPage(
      useShinyjs(),
      )

    다음은 observeEvent 에서 refresh() 를 넣어주면 해당 부분이 실행될 때마다 새로 고침이 된다.

      observeEvent(input$insert_tic, {
        refresh()
      })
  • caret 메세지 안보이게 하기

    caret 패키지에서 분석을 할 경우 특히 neuralnet 기반의 분석에서 메세지가 길게 출력된다. 그냥 두어도 문제는 없으나 반복하여 결과를 실행할 경우 현재 어느 정도 진행되었는지 알기가 어렵다. 그럴 경우 출력 메세지가 안보이도록 하는 요령이다.

    capture.output을 이용하여 출력 메세지를 변수로 받아버린다. 😉

    그런데 이럴 경우 train 결과가 이용되지 않는 것 같다. 아니면 내가 <- 대신 =로 해서 그럴 수도 있겠다.

    garbage <- capture.output(train <- train(Species~.,data=iris,method="nnet",trControl=tc))