[R] dataframe conversion
    Gabor Grothendieck 
    ggrothendieck at gmail.com
       
    Tue Nov  1 18:06:22 CET 2005
    
    
  
On 11/1/05, Uwe Ligges <ligges at statistik.uni-dortmund.de> wrote:
> Pieter Provoost wrote:
> > The data structures in R are still very puzzling to me. Can anyone tell
> > me how I can easily convert these two dataframes to one single dataframe
> > with two columns (mean and sd) with 7 rows?
> >
> >  > meanprofile
> >        V1       V2       V3       V4       V5       V6       V7
> > 2292.001 2178.620 1654.310 1784.004 1160.052 1142.061 1046.675
> >  > sdprofile
> >        V1       V2       V3       V4       V5       V6       V7
> > 310.6714 347.2072 197.2464 532.3916 161.2955 227.3634 108.5017
>
>
> This is quite an unusual task, because you won't have data structure in
> a data.frame most of the times. In particular, you cannot make a row
> from a data.frame to a column generally.
>
> In this case, we just convert the data.frame to matrix. I think most
> easily you can write:
>
>   dat <- t(rbind(meanprofile, sdprofile))
>   colnames(dat) <- c("meanprofile", "sdprofile")
>
Or perhaps:
data.frame(meanprofile = unlist(meanprofile), sdprofile = unlist(sdprofile))
    
    
More information about the R-help
mailing list