[R] create dataframe using structure ()

William Dunlap wdunlap at tibco.com
Thu Mar 13 20:14:12 CET 2014


> I have tried to create a dataframe using the structure() function,
Why do you want to do this?

> but it did not really work.
Use str() or dput() to compare this to a data.frame made in the usual
way.  You have .Names and class being arguments to list() instead of
to structure() and you didn't supply any row.names in the call to structure.

Also, why call your columns "column_<n>" in one place and "row", "stimulation",
... in another?   Is that why you didn't want to call data.frame in the first place,
so you could make the column names variable?

Bill Dunlap
TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Luigi Marongiu
> Sent: Thursday, March 13, 2014 11:59 AM
> To: r-help at r-project.org
> Subject: [R] create dataframe using structure ()
> 
> dear all,
> I have tried to create a dataframe using the structure() function, but it
> did not really work. In column 1 i have the row number, in column 2 and 3
> factors (8 and 4 levels respectively) and in column 4 the actual data.
> any clue on what went wrong?
> best regards
> luigi
> 
> my.data<-structure(list(
> column_1 = 1:32,
> column_2 = structure(c(1, 2, 3, 4, 5, 6, 7, 8,
> 1, 2, 3, 4, 5, 6, 7, 8,
> 1, 2, 3, 4, 5, 6, 7, 8,
> 1, 2, 3, 4, 5, 6, 7, 8),
> .Label =
> c("Unstimulated", "ESAT6", "CFP10", "Rv3615c", "Rv2654", "Rv3879",
> "Rv3873", "PHA"),
> class = "factor"),
> column_3 =
> structure(c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3,
> 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4), .Label = c("bd", "2m", "1m",
> "0.5m"), class = "factor"),
> column_4 =
> c(71.62097178, 2.892223468, 144.8618621, 40.90079262, 37.0516856,
> 32.78206822, 72.44424152, 1512.516293, 3164.748333, 1092.634557,
> 28733.20269, 1207.87783, 729.6090973, 151.8706088, 241.2466141,
> 9600.963594, 682.865522, 5869.375226, 554.8924896, 2982.759858,
> 7690.028092, 40.37298719, 942.3549279, 3403.679967, 103.9862389,
> 35.28562613, 321.5985377, 0.274424607, 3352.874906, 93.76421187,
> 21.3709382, 4193.183281),
> .Names = c("row", "stimulation", "type", "copy"), class = "data.frame"))
> attach(my.data)
> 
> 	[[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