[R] tidyr - gather/spread/separate/unite


[R] tidyr - gather/spread/separate/unite

install.packages('tidyr') library(tidyr) gather(데이터, 새로운 행이름, 새로운 행이름2, 기존 행 이름들) # 기존 행 데이터들을 풀어헤쳐 새로운 행 데이터들로 정렬 # 기존 행 이름들이 새로운 행이름 1로, 기존 행 데이터들이 새로운 행이름 2로 ex) gather(df, location, cost, emart:lottemart) # emart부터 lottemart까지의 행(변수)들이 새로운 행(변수) location의 데이터로 들어감 # emart부터 lottemart까지의 행의 데이터들이 새로운 cost의 데이터로 들어감 spread(데이터, 새로운 칼럼으로 하고싶은 행이름1, 새로운 데이터 행이름2) # gather의 반대방향. 다시 되돌리기 ex) spread(df2, location, cost) # location 데이터가 새로운 칼럼(행, 변수)가 되고, cost가 그 새로운 데이터가 됨. separate(data = 데이터, co...


#gather #R #separate #spread #tidyr #unite

원문링크 : [R] tidyr - gather/spread/separate/unite