[R] arrangement

David Winsemius dwinsemius at comcast.net
Tue Apr 17 03:26:17 CEST 2012


On Apr 16, 2012, at 6:08 PM, Soheila Khodakarim wrote:

> Hi David,
> Thanks a lot for your help.
> But unfortunately I can not understand your mean:(
> Could you explain more for me?
> Best Wishes,
> Soheila


deleted excessive white-space and changed format to plain-text.


object <- structure(list(V1 = structure(c(1L, 3L, 2L), .Label = c("N",
"p", "V"), class = "factor"), V2 = c(4320, 22, 0.640625), V3 = c(3010,
0, 2.910383e-11), V4 = c(514, 15, 0.4257812), V5 = c(604, 15,
0.4375), V6 = c(563, 13, 0.6875), V7 = c(3430, 13, 0.0003356934
), V8 = c(3060, 51, 0.2434998), V9 = c(4140, 20, 0.2783203),
     V10 = c(3050, 62, 0.07714844), V11 = c(562, 273, 0.1044959
     ), V12 = c(565, 265, 0.163799), V13 = c(3022, 27, 0.6523438
     )), .Names = c("V1", "V2", "V3", "V4", "V5", "V6", "V7",
"V8", "V9", "V10", "V11", "V12", "V13"), class = "data.frame",  
row.names = c(NA,
-3L))

Posting only the console output is lame. Learn to post dput()  
output.   (...  or if you prefer, follow the Posting Guide advice and  
use dump(). My preference is dput(), however.)


  new <- t(object[-1])
  new
     [,1] [,2]         [,3]
V2  4320   22 6.406250e-01
V3  3010    0 2.910383e-11
V4   514   15 4.257812e-01
V5   604   15 4.375000e-01
V6   563   13 6.875000e-01
V7  3430   13 3.356934e-04
V8  3060   51 2.434998e-01
V9  4140   20 2.783203e-01
V10 3050   62 7.714844e-02
V11  562  273 1.044959e-01
V12  565  265 1.637990e-01
V13 3022   27 6.523438e-01

colnames(new) <- t(object)[1,]
new
        N   V            p
V2  4320  22 6.406250e-01
V3  3010   0 2.910383e-11
V4   514  15 4.257812e-01
V5   604  15 4.375000e-01
V6   563  13 6.875000e-01
V7  3430  13 3.356934e-04
V8  3060  51 2.434998e-01
V9  4140  20 2.783203e-01
V10 3050  62 7.714844e-02
V11  562 273 1.044959e-01
V12  565 265 1.637990e-01
V13 3022  27 6.523438e-01

If you want this to be a data.frame use as.data.frame()
-- 
David.




> On Tue, Apr 17, 2012 at 1:55 AM, David Winsemius <dwinsemius at comcast.net 
> > wrote:
>
> On Apr 16, 2012, at 5:19 PM, Soheila Khodakarim wrote:
>
> Dear All
>
> I want to arrange our output in 3 columns in R.
> Example:
>
> N           04320        03010      00514   00604   00563        03430
> 03022
> V 22.000000 0.000000e+00 15.0000000 15.0000 13.0000 1.300000e+01  
> 51.0000000
> p  0.640625 2.910383e-11  0.4257812  0.4375  0.6875 3.356934e-04   
> 0.2434998
>
> N     03060       04140       03050      00562      00565
> V 20.0000000 62.00000000 273.0000000 265.000000 27.0000000
> p  0.2783203  0.07714844   0.1044959   0.163799  0.6523438
>
> arranged:
>
> N                    P                         V
> 04320          22.000000         0.640625
> 03010         0.000000e+00   2.910383e-11
>
> Is there any way to do it in R directly?
>
> ?t
>
> (Type the above two character at your console.)
>
> You may also need object[ , c(1,3,2)]
>
>
>
> Best Regards,
> Soheila
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
> David Winsemius, MD
> West Hartford, CT
>
>

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list