在R上创建一个具有一行和零值的数据框架
我想创建一个带有单行的数据框,其中列“日期”,“ 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于一个空数据框,您可以使用类(例如,
targe
)初始化向量。如果您需要日期格式,则可以将aS.date
围绕targin
包装。或者,如果您需要一个实际的行,则可以使用
na
。但这默认为课堂的逻辑。因此,如果您需要列是特定的类,那么您仍然需要围绕na
(例如,as.character(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 wrapas.Date
aroundcharacter
.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 theNA
(e.g.,as.character(NA)
).You can use
NULL
as character, but I don't think it's possible to have only aNULL
row.这似乎也可以工作:
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)