[R] creating horizontal dataframes with column names

Alexy Khrabrov deliverable at gmail.com
Wed Sep 17 07:27:40 CEST 2008


Exactly -- also found creating horizontal vector helps:

 > df <- data.frame(matrix(1:5,nrow=1))
 > colnames(df) <- LETTERS[1:5]
 > df
   A B C D E
1 1 2 3 4 5

Thanks,
Alexy

On Sep 17, 2008, at 1:17 AM, Moshe Olshansky wrote:

> If df is your data.frame, then
> colnames(df) <- c("col1","Col2","COL3")
>
>
>
> --- On Wed, 17/9/08, Alexy Khrabrov <deliverable at gmail.com> wrote:
>
>> From: Alexy Khrabrov <deliverable at gmail.com>
>> Subject: [R] creating horizontal dataframes with column names
>> To: r-help at stat.math.ethz.ch
>> Received: Wednesday, 17 September, 2008, 1:52 PM
>> Greetings -- in order to write back to SQL databases, one
>> needs to
>> create a dataframe with values.  I can get column names of
>> an existing
>> table with sqlColumns.  Say I have a vector of values (if
>> they're all
>> the same type), or a list (if different).  How do I create
>> a dataframe
>> with column names given by my sqlColumns?  To make it
>> concrete, how do
>> we make a dataframe
>>
>> A B C
>> 1 2 3
>>
>> out of
>>
>> column.names <- LETTERS[1:3]
>> values <- 1:3
>>
>> ?
>> Cheers,
>> Alexy
>>
>> ______________________________________________
>> 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