1
One <- c(rep("X",6),rep("Y",3),rep("Z",2))
Two <- c(rep("Blue",4),rep("Red",7))
Three <- c(rep("A",4),rep("B",6),rep("C",1))
Four <- c(rep("Green",5),rep("Black",6))
df1 <- cbind(One,Two)
df2 <- cbind(Three,Four)
df.final <- as.data.frame(rbind(df1,df2))
Month <- c(rep("January",nrow(df1)), rep("February",nrow(df2)))
cbind(Month,df.final)
Month One Two
1 January X Blue
2 January X Blue
3 January X Blue
4 January X Blue
5 January X Red
6 January X Red
7 January Y Red
8 January Y Red
9 January Y Red
10 January Z Red
11 January Z Red
12 February A Green
13 February A Green
14 February A Green
15 February A Green
16 February B Green
17 February B Black
18 February B Black
19 February B Black
20 February B Black
21 February B Black
22 February C Black
一切都是花花公子,但我的问题是Month <- c(rep("January",nrow(df1)), rep("February",nrow(df2)))
我将有12个数据帧,并希望大的向量与每个月的频率对应于我拥有的12个数据帧中的每一个的向量。直觉上,我认为像这样的工作:
lapply(c(months*),function(x) rep(x,nrow(c(list of 12 dataframes))##pseudo code
我试图避免做Months <- c(rep("Jan",nrow(jan.df)),rep("Feb",nrow(feb.df)),...,rep("Dec",nrow(def.df)))
在我要cbind
这个矢量的所有月份dataframes的rbind
末。就像在这个例子中,除了那里只有两个月。
不清楚您预期的结果。 – akrun