티스토리 뷰

# 문제 : 월드시리즈 AL vs NL 어느 리그가 더 많이 이겼는가?

# 자료수집(직접 입력)
NL <- c("FLA", "STL", "HOU", "STL", "COL",
        "PHI", "PHI", "SFG", "STL", "SFG",
        "STL", "SFL", "NYM")
AL <- c("NYY", "BOS", "CHW", "DET", "BOS",
        "TBR", "NYY", "TEX", "TEX", "DET",
        "BOS", "KC", "KC")
Winner <- c("NL", "AL", "AL", "NL", "AL",
            "NL", "AL", "NL", "NL", "NL",
            "AL", "NL", "AL")
N.Games <- c(6,4,4,5,4,5,6,5,7,4,6,7,5)
Year <- 2003:2015

# 자료구조를 행렬(matrix)로 변경

results <- matrix(c(NL, AL), length(NL), 2)
  # results <- matrix(c(NL, AL), 10, 2) : NOT a sub-multiple or multiple of the number of rows[10]
results

# 'dimnames' : add descriptive labels to the rows and columns of the matrix
dimnames(results)[[1]] <- Year
dimnames(results)[[2]] <- c("NL Team", "AL Team")
results

# 'table' construct a frequency table for a vector of character data.
table(Winner)

# AL 6 : NL 7  => 내셔널리그 우세

# 그래프로 나타내기

# a bar graph of the frequencies
barplot(table(Winner))

 

댓글