RStudio数据浏览器中c(...)的含义 [英] Meaning of c(...) in RStudio's data browser

查看:330
本文介绍了RStudio数据浏览器中c(...)的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道,在 RStudio 中工作并在 R View()时>模块,找到该模块将导致打开RStudio的内部数据浏览器窗口。尽管大多数简单数据都是可以理解的,但我对这样的数据感到困惑: c(NA,NA,NA,125125,NA)。它代表什么?看起来像矢量的标准 R 表示法。但是,我希望在该位置出现嵌入式 数据框

As you know, when working in RStudio and calling View() in R module, sourcing this module results in opening RStudio's internal data browser window. While most simple data is understandable, I'm confused by seeing data like this: c(NA, NA, NA, 125125, NA). What does it represent? This looks like standard R notation for vectors. However, I expect an embedded data frame in that spot. Would appreciate clarification!

推荐答案

c(...)确实可以!这是RStudio数据浏览器中的向量。这是一个最小的可复制示例。

c(...) does indeed mean "vector" in RStudio's data browser.. Here's a minimal reproducible example.

set.seed(1)
df1   <- data.frame(id=LETTERS[1:10])
# each element of df1$x is char
df1$x <- sapply(1:10,function(i)do.call(paste,as.list(letters[sample(1:10,5)])))
# each element of df2$x is a vector of char
df2   <- aggregate(x~id,df1,function(x)strsplit(as.character(x)," "))
View(df2)

在上面, df1 $ x 的每个元素都是一个字符串,包含5个随机,以空格分隔的字符。在此示例中,集合函数对每个 df1 $ x 的值运行 strsplit(...)一个字符向量,存储在 df2 $ x 的元素中。因此,当您在RStudio中 View(df2)时,它反映了一个事实,即 df2 $ x 的每个元素都是一个向量。

In the above, each element of df1$x is a character string with 5 random, space-separated characters. The "aggregate" function in this example runs strsplit(...) on each value of df1$x to return a vector of characters, which are stored in the elements of df2$x. So when you View(df2) in RStudio, it reflects the fact that each element of df2$x is a vector.

编辑(响应OP的评论)

这将创建一个数据框( df1 ),其中 df1 $ z 的每个元素都是一个数据框。

This creates a dataframe (df1) where each element of df1$z is a dataframe.

df1   <- data.frame(id=LETTERS[1:3])
df    <- data.frame(id=rep(letters[1:3],each=10),x=rnorm(30), y=rnorm(30))
df1$z <- split(df,df$id)
View(df1)

请注意,RStudio将 df1 $ z 显示为列表向量,实际上是数据帧的基础结构。

Note that RStudio displays df1$z as a list of vectors, which is, in fact, the underlying structure of a dataframe.

这篇关于RStudio数据浏览器中c(...)的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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