gpt4 book ai didi

重新排序数据框列表

转载 作者:行者123 更新时间:2023-12-05 05:08:01 24 4
gpt4 key购买 nike

我有一个数据框列表:

set.seed(1)
S1 = data.frame(replicate(2,sample(0:130,30,rep=TRUE)))
S2 = data.frame(replicate(2,sample(0:130,34,rep=TRUE)))
S3 = data.frame(replicate(2,sample(0:130,21,rep=TRUE)))
S4 = data.frame(replicate(2,sample(0:130,26,rep=TRUE)))
df_list1 = list(S1 = S1, S2 = S2, S3 = S3, S4 = S4)

set.seed(2)
S1 = data.frame(replicate(2,sample(0:130,30,rep=TRUE)))
S2 = data.frame(replicate(2,sample(0:130,34,rep=TRUE)))
S3 = data.frame(replicate(2,sample(0:130,21,rep=TRUE)))
S4 = data.frame(replicate(2,sample(0:130,26,rep=TRUE)))
df_list2 = list(S1 = S1, S2 = S2, S3 = S3, S4 = S4)

set.seed(3)
S1 = data.frame(replicate(2,sample(0:130,30,rep=TRUE)))
S2 = data.frame(replicate(2,sample(0:130,34,rep=TRUE)))
S3 = data.frame(replicate(2,sample(0:130,21,rep=TRUE)))
S4 = data.frame(replicate(2,sample(0:130,26,rep=TRUE)))
df_list3 = list(S1 = S1, S2 = S2, S3 = S3, S4 = S4)

set.seed(4)
S1 = data.frame(replicate(2,sample(0:130,30,rep=TRUE)))
S2 = data.frame(replicate(2,sample(0:130,34,rep=TRUE)))
S3 = data.frame(replicate(2,sample(0:130,21,rep=TRUE)))
S4 = data.frame(replicate(2,sample(0:130,26,rep=TRUE)))
df_list4 = list(S1 = S1, S2 = S2, S3 = S3, S4 = S4)

df_list = list (df_list1, df_list2, df_list3, df_list4)
names(df_list) = c("AB_df", "BC_df", "DE_df", "FG_df")

df_list = unlist(df_list, recursive = FALSE)

现在我想重新排列列表中数据帧的顺序。模式应为 1,5,9,13, 2,6,10,14,3,7,11,15,4,8,12,16

我是这样编程的:

subs = 4 # Need the subs, since I have different numbers for this
idx = seq (1, length(df_list), subs)
nameorder = c(names(df_list[idx]), names(df_list[idx+1]),
names(df_list[idx+2]),names(df_list[idx+3]))

我现在的问题是,如何使用 nameorder 列表来更改我的 df_list(应保留名称)。我想这很简单,但我就是做不到。

最佳答案

您可以尝试如下所示的简单命令 df_list 来重新排序 data frames 列表:

df_list[nameorder]

关于重新排序数据框列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58610549/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com