创建具有多个数据框的文件 [英] Creating a file with more than one data frame

查看:116
本文介绍了创建具有多个数据框的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是R的新手,所以如果这是一个基本问题,我提前道歉,但我已经搜索高低,但没有找到答案。

I am new to R, so I apologize in advance if this is an elementary question, but I have searched high and low but have not found an answer.

我想制作一个包含多个数据框的文件。 (一个例子是BradleyTerry2软件包中的数据集flatlizards,该文件称为flatlizards,但其中有两个数据框 - contests和predictors。当你要求查看数据flatlizards时两个数据帧都在它们相应的标题下分别示出)。

I would like to make a file with more than one data frame within it. (An example is the dataset "flatlizards" in the BradleyTerry2 package. The file is called "flatlizards" but there are two data frames within it--"contests" and "predictors." When you ask to see the data "flatlizards" the two data frames are both shown separately under their corresponding headings).

如何将两个单独命名的数据框连接到一个文件中?此外,我如何这样做与CSV文件?所有数据需要在一个CSV文件还是多个文件?谢谢提前,我真的很感激的帮助。

How do I connect two separately-named data frames into one file? Also, how do I do this with CSV files? Do all the data need to be in one CSV file, or multiple files? Thank you in advance, I really appreciate the help.

推荐答案

有问题的对象是一个列表。您可以使用以下代码查看此内容:

The object in question is a list. You can see this by using the following code:

library(BradleyTerry2)
data(flatlizards)
str(flatlizards)

你可以看到它是一个2的列表,

You can see it is a list of 2, and its elements are the separate data frames.

您可以很容易地将对象组合在一个列表中:

You can combine objects together in a list like this quite easily:

a <- data.frame(x=rnorm(10), y=runif(10))
b <- data.frame(w=rnorm(20), z=runif(20))

ablist <- list(a, b)

或者,如果你想要它们在一个数据框或一个csv,你可以尝试使用 merge

Alternatively, if you want them in one dataframe or one csv, you can try using merge.

这篇关于创建具有多个数据框的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆