R

· R
정의 function_name = function ( arguments ) body Editor program is useful to write a long program including R function. R program provides an editor but there are several editors or IDEs freely available for R programming. (for example, Tinn-R, RStudio) 함수의 정의 rm( list = ls() ) my.mean = function( data ) sum( data ) / length( data ) ls() ## [1] "my.mean" my.mean ## function( data ) sum( data ) / l..
· R
작성일자 : 2023-09-29 Ver 0.1.1 if() function if( cond ) expr if( cond ) cond.expr else alt.expr x = 1:5 x ## [1] 1 2 3 4 5 y = -2:2 y ## [1] -2 -1 0 1 2 if ( any( x < 0 ) ) print( x ) # print() is not executed if ( any( y < 0 ) ) print( abs( y ) ) # print() is executed ## [1] 2 1 0 1 2 if ( any( y < 0 ) ) { print( abs( y ) ) print( 'y contains negative values' ) } ## [1] 2 1 0 1 2 ## [1] "y contain..
· R
작성일자 : 2023-09-29 Ver 0.1.1 Data frame은 자료분석을 위해 만들어진 객체형이다. Data frame은 여러면에서 matrix 및 list와 유사한 형태를 지닌다 Data frame의 행(row)은 샘플(observations)에 대응되며 열(column)은 변수(variables)에 대응된다. Data frame 만들기: read.table() data1 = read.table( 'files/data1.txt' ) data1 ## V1 V2 V3 V4 ## 1 no name age sex ## 2 1 LEE 55 M ## 3 2 PARK 47 F ## 4 3 SO 35 M ## 5 4 KIM 26 F ## 6 5 YOON 29 M data2 = read.table( 'file..
· R
작성일자 : 2023-09-29 Ver 0.1.1 지금까지 살펴본 객체형들과 다르게, list 객체는 상이한 자료형을 갖는 원소들을 포함할 수 있으며, 원소의 길이도 동일할 필요가 없다. List의 원소를 성분(component)이라고 부른다. List 만들기 mat1 = matrix( 1:4 , nrow = 2 ) list1 = list( 'A' , 1:8 , mat1 ) list1 ## [[1]] ## [1] "A" ## ## [[2]] ## [1] 1 2 3 4 5 6 7 8 ## ## [[3]] ## [,1] [,2] ## [1,] 1 3 ## [2,] 2 4 student = list( student.name = c( 'Jake' , 'Jason' , 'Ashley' ), student.cnt ..
Unlimited Jun
'R' 카테고리의 글 목록