在R上创建一个具有一行和零值的数据框架

发布于 2025-01-21 12:04:55 字数 200 浏览 3 评论 0原文

我想创建一个带有单行的数据框,其中列“日期”,“ p.Value”和“用户”列值,但是我不在下面的代码上使用:

df <- data.frame(Date=NULL, "p.value"=NULL, User=NULL)

有人知道如何解决它吗?

I would like to create a dataframe with a single line with NULL values for the columns "Date", "p.value" and "User", but I'm not suceeding with the code below:

df <- data.frame(Date=NULL, "p.value"=NULL, User=NULL)

Does anyone know how to solve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愿得七秒忆 2025-01-28 12:04:55

对于一个空数据框,您可以使用类(例如,targe)初始化向量。如果您需要日期格式,则可以将aS.date围绕targin包装。

df <- data.frame(Date=as.Date(character()),
                 "p.value"=character(), 
                 User=character(), 
                 stringsAsFactors=FALSE)

#[1] Date    p.value User   
#<0 rows> (or 0-length row.names)

或者,如果您需要一个实际的行,则可以使用na。但这默认为课堂的逻辑。因此,如果您需要列是特定的类,那么您仍然需要围绕na(例如,as.character(na))包裹类。

df <- data.frame(Date=NA, "p.value"=NA, User=NA, 
                 stringsAsFactors=FALSE)

#  Date p.value User
#1   NA      NA   NA

您可以将null用作字符,但我认为只能只有null行。

For an empty dataframe, you can initialize a vector with the class (e.g., character). If you are needing a date format, then you can wrap as.Date around character.

df <- data.frame(Date=as.Date(character()),
                 "p.value"=character(), 
                 User=character(), 
                 stringsAsFactors=FALSE)

#[1] Date    p.value User   
#<0 rows> (or 0-length row.names)

Or you could use NA if you need an actual row. But this defaults to logical for class. So, if you need columns to be a particular class, then you would still need to wrap the class around the NA (e.g., as.character(NA)).

df <- data.frame(Date=NA, "p.value"=NA, User=NA, 
                 stringsAsFactors=FALSE)

#  Date p.value User
#1   NA      NA   NA

You can use NULL as character, but I don't think it's possible to have only a NULL row.

甜心 2025-01-28 12:04:55

这似乎也可以工作:

xcemens_df&lt; - data.frame(“ date” = targine(0),“ p.value” = integer(0),“ user” = integer(0))>

提出了这一点:

[1]日期P.Value用户
&lt; 0行&gt; (或0个长度行。名称)

This seems to work too:

example_df <- data.frame( "date" = character(0), "p.value" = integer(0), "USER" = integer(0))

Comes up with this:

[1] date p.value USER
<0 rows> (or 0-length row.names)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文