views:

102

answers:

2

I have a data frame that I am outputting to MS Word. Lets say I'm trying to output the data frame mtcars, then using the R2wd package, I get:

#install.packages("R2wd")
require(R2wd)
wdGet()
wdTable(mtcars)

'>ncol(mtcars)
11

however a count shows that there are actually 12 columns. R doesn't include the model of car.

I have a dataframe that's outputting the numeric sequence of a dataframe and I really need that suppressed. In the report I'm outputting to it's useless information. So I basically need to suppress the model column of mtcars.

Also, how is it that they can get the car names to be the "hidden" column?

+3  A: 

All data.frame objects have rowname attributes. You're confusing the rowname for an actual column.

> str(mtcars)
'data.frame':   32 obs. of  11 variables:
 $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
 $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...
 $ disp: num  160 160 108 258 360 ...
 $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...
 $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
 $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...
 $ qsec: num  16.5 17 18.6 19.4 17 ...
 $ vs  : num  0 0 1 1 0 1 0 1 1 1 ...
 $ am  : num  1 1 1 0 0 0 0 0 0 0 ...
 $ gear: num  4 4 4 3 3 3 3 4 4 4 ...
 $ carb: num  4 4 1 1 2 1 4 2 2 4 ...
> rownames(mtcars)
 [1] "Mazda RX4"           "Mazda RX4 Wag"       "Datsun 710"         
 [4] "Hornet 4 Drive"      "Hornet Sportabout"   "Valiant"            
 [7] "Duster 360"          "Merc 240D"           "Merc 230"           
[10] "Merc 280"            "Merc 280C"           "Merc 450SE"         
[13] "Merc 450SL"          "Merc 450SLC"         "Cadillac Fleetwood" 
[16] "Lincoln Continental" "Chrysler Imperial"   "Fiat 128"           
[19] "Honda Civic"         "Toyota Corolla"      "Toyota Corona"      
[22] "Dodge Challenger"    "AMC Javelin"         "Camaro Z28"         
[25] "Pontiac Firebird"    "Fiat X1-9"           "Porsche 914-2"      
[28] "Lotus Europa"        "Ford Pantera L"      "Ferrari Dino"       
[31] "Maserati Bora"       "Volvo 142E"         
Joshua Ulrich
+1  A: 

In the mtcars data.frame, they have set the rownames for the data.frame = the name of the car. You can check this out by doing something like this:

data(mtcars)
rownames(mtcars)

You can also set the rownames for an object. From the help page:

m2 <- cbind(1,1:4)
rownames(m2) <- rownames(m2, do.NULL = FALSE, prefix = "Obs.")

The equivalent funcitonality exists with colnames.

Chase