[R] create a data frame with the given column names

Sascha Vieweg saschaview at gmail.com
Thu Feb 17 11:07:18 CET 2011


On 11-02-16 16:29, Sam Steingold wrote:

> how do I create a data frame with the given column names
> _NOT KNOWN IN ADVANCE_?
> i.e., I have a vector of strings for names and I want to get an _EMPTY_
> data frame with these column names.
> is it at all possible?

Read the posting guide, provide example code. Then you could start 
here:

vstr <- sample(letters, sample(1:20, 1), repl=F)
df <- as.data.frame(matrix(ncol=length(vstr), dimnames=list(NULL, 
vstr)))
str(df)

HTH, *S*

-- 
Sascha Vieweg, saschaview at gmail.com



More information about the R-help mailing list