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? -- Sam Steingold (http://sds.podval.org/) on CentOS release 5.3 (Final) http://openvotingconsortium.org http://pmw.org.il http://memri.org http://mideasttruth.com http://palestinefacts.org I don't like cats! -- Come on, you just don't know how to cook them!
On 2011-02-16 13: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? >It's not really clear to me what you want to do. If you want to create a zero-rows dataframe (why?), here's one way: nm <- letters[11:14] d <- as.data.frame( matrix(nrow = 0, ncol = 4, dimnames = list(NULL, nm))) Peter Ehlers
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