如何删除在 R 中使用 unstack 时出现的排序?

How do I remove the sorting that comes when I use unstack in R?

我已经在 R 中创建了一个列表,按照以下行:

alist <- as.list(unstack(DF, DF[,1]~DF[,2]))

我这样做是使用 unstack,我了解到它适用于排序——这意味着键是按字母数字顺序排序的。

不幸的是,稍后,我需要按 lapply 中的位置访问这些值。我需要按照它们插入列表的顺序访问它们。

有什么方法可以取消 unstack 的排序吗?

unstack负责排序。尝试像 as.list(unstack(DF, DF[,1]~DF[,2])[unique(DF[,2])]) 这样的东西。 list等同于Python的OrderedDict.