[R] data.frame() creates list?

Henrik Bengtsson hb at stat.berkeley.edu
Thu Aug 21 02:46:53 CEST 2008


It is a data.frame.  They are represented by lists.

df <- data.frame(a=1:2, b=letters[1:2]);
> str(df)
'data.frame':   2 obs. of  2 variables:
 $ a: int  1 2
 $ b: Factor w/ 2 levels "a","b": 1 2
> class(df);
[1] "data.frame"
> mode(df);
[1] "list"
> typeof(df);
[1] "list"

For details, see code, e.g. page(data.frame).

/Henrik

On Wed, Aug 20, 2008 at 5:33 PM, Farley, Robert <FarleyR at metro.net> wrote:
> I obviously don't know what I'm doing.  I want to create "ByEBNum" as a
> data frame, but it comes out as a list.  How do I make it a data frame?
>
>
>
>
>
>> EBNumStn <- c(673.65,     800, 1000, 1000,  800,  700,  600, 500, 400,
> 200,  50, 50 )
>
>> ByEBNum <- data.frame(c(1:12),EBNumStn)
>
>> typeof(EBNumStn)
>
> [1] "double"
>
>> typeof(c(1:12))
>
> [1] "integer"
>
>> typeof(ByEBNum)
>
> [1] "list"
>
>> ByEBNum
>
>   c.1.12. EBNumStn
>
> 1        1   673.65
>
> 2        2   800.00
>
> 3        3  1000.00
>
> 4        4  1000.00
>
> 5        5   800.00
>
> 6        6   700.00
>
> 7        7   600.00
>
> 8        8   500.00
>
> 9        9   400.00
>
> 10      10   200.00
>
> 11      11    50.00
>
> 12      12    50.00
>
>>
>
>
>
>>sessionInfo()
>
> R version 2.7.1 (2008-06-23)
>
> i386-pc-mingw32
>
>
>
> locale:
>
> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> States.1252;LC_MONETARY=English_United
> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>
>
>
> attached base packages:
>
> [1] graphics  grDevices utils     datasets  stats     methods   base
>
>
>
>
> other attached packages:
>
> [1] survey_3.8     fortunes_1.3-5 moonsun_0.1    prettyR_1.3-2
> foreign_0.8-28
>
>>
>
>
>
>
>
>
>
>
>
>
>
> Robert Farley
>
> Metro
>
> 1 Gateway Plaza
>
> Mail Stop 99-23-7
>
> Los Angeles, CA 90012-2952
>
> Voice: (213)922-2532
>
> Fax:    (213)922-2868
>
> www.Metro.net
>
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list