본문 바로가기

R

(11)
[R] ggplot density chart Code Ref. https://www.r-graph-gallery.com/21-distribution-plot-using-ggplot2.html Basic density chart with ggplot2 Learn how to build a basic density chart with ggplot2. Reproducible R code is provided. www.r-graph-gallery.com data source https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/1_OneNum.csv # Libraries library(ggplot2) library(dplyr) library(hrbrthemes) # Load..
[R] correlation # correlation table cor(df) # 숫자형 열만 선택하여 correlation # dplyr::select_if cor(select_if(cor, is.numeric()) # na 있는 행 제외하고 숫자형 열만 선택하여 correlation cor(select_if(df[complete.cases(df),], is.numeric))
[R] ggplot color palette # ggplot color palette 사용 # scale_colour_brewer(palette='palette_name') mpg %>% ggplot(aes(x = cty, y = hwy)) + geom_point(aes(color = factor(class))) + scale_colour_brewer(palette="Paired") # palette 역순으로 사용 시 # scale_colour_brewer(palette="palette_name", direction = -1) mpg %>% ggplot(aes(x = cty, y = hwy)) + geom_point(aes(color = factor(class))) + scale_colour_brewer(palette="Paired", direct..
[R package] lubridate # df의 time이 date 형식일 때, year, month 추출 # year year(df$time) # month month(df$time)
[R] category 형 변수 Label encoding # data 내 category 형 변수를 factor 사용하여 숫자로 label encoding ex.) train 내 col_A라는 변수가 category형일 때 숫자로 label encoding 한 후 저장 train$col_A
[R] data.frame을 클립보드 복사 # data.frame이나 table을 클립보드로 복사 ex) df라는 data.frame을 클립보드로 복사할 때(index없이) write.table(df, "clipboard", sep = "\t", row.names = FALSE)
[R] 결측치 처리 # 결측치를 특정 값으로 대체 ex) df내 col_A 열의 결측치를 모두 0으로 대체 하여 저장 * replace_na() 사용 df % replace_na(list(col_A = 0)) * 행 조회하여 변경 df[is.na(col_A),'col_A']
[R] 특정 열 제외 # 특정 열 제외하여 저장 ex.) df 의 'col_A' 라는 열 제외 df