English 中文(简体)
结构中的“等级”参数是什么?
原标题:what is the "class" parameter in structure()?
  • 时间:2011-11-23 19:35:21
  •  标签:
  • r

I am trying to use the structure() function to create a data frame in R. I saw something like this

structure(mydataframe, class="data.frame")

哪里是班子? 我看到有人使用这一工具,但并未列入R文件。

这名方案人员是否以另一种语言学习,并接下去? 并且是行之有效的。 我感到非常困惑。

Edit: I realized dput(), is what actually created a data frame looking like this. I got it figured out, cheers!

最佳回答

您可能看到有人使用<代码>dput<>。 但是,通常你不会建立这样的数据框架。 通常由<代码>数据>创建。 见下文。

> example_df <- data.frame(x=rnorm(3),y=rnorm(3))
> example_df
           x          y
1  0.2411880  0.6660809
2 -0.5222567 -0.2512656
3  0.3824853 -1.8420050
> dput(example_df)
structure(list(x = c(0.241188014013708, -0.522256746461544, 0.382485333260912
), y = c(0.666080872170054, -0.251265630627216, -1.84200501106852
)), .Names = c("x", "y"), row.names = c(NA, -3L), class = "data.frame")

然后,如果有人想要“复印”你<代码>数据.frame,他就不得不操作如下:

> copied_df <- structure(list(x = c(0.241188014013708, -0.522256746461544, 0.382485333260912
+     ), y = c(0.666080872170054, -0.251265630627216, -1.84200501106852
+     )), .Names = c("x", "y"), row.names = c(NA, -3L), class = "data.frame")

我将“范围”放在引文中,因为我注意到:

> identical(example_df,copied_df)
[1] FALSE
> all.equal(example_df,copied_df)
[1] TRUE

identical yields false because when you post your dput output, often the numbers get rounded to a certain decimal point.

问题回答

班级不是<条码>结构功能的具体论点,这就是为什么你没有在帮助档案中找到。

带有物体,然后是任何名称/数值的鞋子,将其列为物体的属性。 在此情况下,<代码>就是这种属性。 你们可以尝试把虚构的oo和 bar特性添加到病媒中:

x <- structure(1:3, foo=42, bar= hello )
attributes(x)
#$foo
#[1] 42
#
#$bar
#[1] "hello"

正如Joshua Ulrich和Kil Wang提到的那样,你不应创建<条码>数据。 类似情况。

我祝贺我的负责人,问“R Document”不会说什么是“阶级”。 它是语言的一个基本组成部分,也是如何运用职能。 您应为:

?class
?methods




相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签