각 문항별로 R code와 수행결과를 모두 제출하시오

1. abalone-new.csv에는 1995년 개인이 수집한 전복에 관련된 자료가 저장되어 있다.각 변수에 대한 설명은 다음과 같다.
1) 자료 파일을 읽어 abalone이름의 data frame을 만드시오.
abalone <- read.csv("C:/Users/qkrgp/Documents/RData/abalone.csv")

결과 이미지 : alt text

head 확인

head(abalone)

결과 이미지 : alt text

2) abalone 자료중 범주형 변수는 어떤 것들이 있는지 살펴보고 해당 범주형 변수를 수업시간에 배운 내용을 바탕으로 살펴보시오.
  1. 범주형 변수 확인하기
categorical_vars <- sapply(abalone, is.factor)

결과 이미지 : alt text

  1. 범주형 변수의 고유값 살펴보기
lapply(abalone[categorical_vars], unique)

수행결과 : named list()

3) Age별 Ring, Diameter의 분포 살펴보기
  1. Age별 Ring의 분포
boxplot(Rings ~ Age, data = abalone, main = "Rings by Age", xlab = "Age", ylab = "Rings")

결과 이미지 : alt text

  1. Age별 Diameter의 분포
boxplot(Diameter ~ Age, data = abalone, main = "Diameter by Age", xlab = "Age", ylab = "Diameter")

결과 이미지 : alt text

4) 4가지 weight의 분포가 Age 별로 다른지 살펴보기
melted_abalone <- melt(abalone, id.vars = c("Age", "Length", "Diameter", "Height", "Rings"), 
                       measure.vars = c("Whole_Weight", "Shucked_Weight", "Viscera_Weight", "Shell_Weight"))

ggplot(melted_abalone, aes(x = Age, y = value, fill = Age)) + 
    geom_boxplot() + 
    facet_wrap(~variable, scales = "free_y") + 
    labs(title = "Weight Distribution by Age", x = "Age", y = "Weight")

결과 이미지 : alt text

5) Whole_weight와 크기 관계 살펴보기
pairs(~Whole_Weight + Length + Diameter + Height, data = abalone, main = "Relationships between Whole Weight and Dimensions")

결과 이미지 : alt text

6) 7개 연속변수 산점도 행렬 살펴보기
pairs(~Length + Diameter + Height + Whole_Weight + Shucked_Weight + Viscera_Weight + Shell_Weight, 
      data = abalone, 
      main = "Scatterplot Matrix of Continuous Variables")

결과 이미지 : alt text