Skip to content

Instantly share code, notes, and snippets.

@enujo
Created July 26, 2017 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enujo/9b7b2515915994c8c484e79fb79daa5b to your computer and use it in GitHub Desktop.
Save enujo/9b7b2515915994c8c484e79fb79daa5b to your computer and use it in GitHub Desktop.
getwd()
# 리스트 생성 : listData
listData <- list("홍길동",550000, T)
listData
v <- c(1:5)
m <- matrix(c(1:6), nrow=2)
# 리스트에서 값의 태그는선택적 요소이지만 값을 나타내는 인덱스보다 태그명을 붙이는것이 조금더 명확하다.
listData <- list(name="홍길동",salary=550000, union=T)
listData
# 리스트에서 하나의 요소값을 선택할때 방법
listData$name
listData["name"] # 네임테그가 아니라 네임이라는게 있어 그걸 출력할거니? 정확하게 지정하지 않았다.
listData[["name"]] # $name과 같다
class(listData["name"]) #list
class(listData[["name"]]) #character
# 리스트를 선언하고 그 값을 입력
vecList <- vector(mode="list")
vecList$name="김은탁" #요즘에는 = 을 써도 가능
vecList$salary=550000
vecList$union <- F
vecList
# 리스트를 벡터로 변환하는 함수 : unlist()
# vector는 같은 데이터 형으로만 만들어 진다 ==> 데이터형을 하나로 통합
exData<-unlist(vecList)
exData
#l은 리스트 s 는 vector summary같은 경우에는 배열로
# apply함수군 사용
exListData <- list(1:4,30:55)
exListData <- list(c(1:4),c(30:55))
exListData
# 리스트의 합
sum <-lapply(exListData, sum)
sum
sum <-sapply(exListData, sum)
sum
# 리스트의 분산
listVar <-lapply(exListData, var)
listVar
listVar <-sapply(exListData, var)
listVar
# 리스트의 표준편차
listSd <-lapply(exListData, sd)
listSd
listSd <-sapply(exListData, sd)
listSd
# 리스트의 기초통계량
listSummary <-lapply(exListData, summary)
listSummary
listSummary <-sapply(exListData, summary)
listSummary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment