[R] create dataframe using structure ()

arun smartpink111 at yahoo.com
Thu Mar 13 20:42:35 CET 2014


Hi,
Try:
 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 = structure(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"), row.names= c(NA,-32L), class = "data.frame")

str(my.data)
'data.frame':    32 obs. of  4 variables:
 $ row        : int  1 2 3 4 5 6 7 8 9 10 ...
 $ stimulation: Factor w/ 8 levels "Unstimulated",..: 1 2 3 4 5 6 7 8 1 2 ...
 $ type       : Factor w/ 4 levels "bd","2m","1m",..: 1 1 1 1 1 1 1 1 2 2 ...
 $ copy       : num  71.62 2.89 144.86 40.9 37.05 ...

A.K.


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)




More information about the R-help mailing list