在R中重新设置数据帧的范围
我在R中有一个data.frame,如下所示:在R中重新设置数据帧的范围,r,R,我在R中有一个data.frame,如下所示: df <- data.frame(date=c(1,2,1,2), id=c(11,11,22,22), x=c(1,2,3,4)) 你怎么能做到?执行此类任务的一般方法是什么?使用重塑 reshape(df, direction="wide", timevar="id", idvar="date") # date x.11 x.22 # 1 1 1 3 #
df <- data.frame(date=c(1,2,1,2), id=c(11,11,22,22), x=c(1,2,3,4))
你怎么能做到?执行此类任务的一般方法是什么?使用
重塑
reshape(df, direction="wide", timevar="id", idvar="date")
# date x.11 x.22
# 1 1 1 3
# 2 2 2 4
reshape(df, direction="wide", timevar="id", idvar="date")
# date x.11 x.22
# 1 1 1 3
# 2 2 2 4