2016년 1월 9일 토요일

[R] Reshape

#Reshape

install.packages("reshape")
library(reshape)

x1<-c(1, 1, 2, 2)
x2<-c(1, 2, 1, 2)
x3<-c(5, 3, 6, 2)
x4<-c(6, 5, 1, 4)

mydata<-data.frame(x1, x2, x3, x4)
colnames(mydata)<-c("id", "time", "male", "female")
mdata <- melt(mydata, id=c("id","time"))
mydata
mdata

submeans<-cast(mdata, id~variable, mean)
timemeans <- cast(mdata, time~variable, mean)
submeans
timemeans

# rename the variable names
library(reshape)

test <- rename(test, c(target="newname"))

댓글 없음:

댓글 쓰기