[BioC] Basic R question

Heidi Dvinge heidi at ebi.ac.uk
Thu Jul 14 16:47:45 CEST 2011


If X is your data.frame, try

X.chrom <- split(X, X$chrom)

This will create a list, with a dataframe for eah unique entry in the
"chrom" column.

HTH
\Heidi

> HI ,
> I want to subset a list I have in order to look only the data from
> chosen chromosomes.
> my file is this format ( see attached for a workable example) . This
> dataframe contain 6 columns, ID (X10th.txt., X11th.txt..),
> chrom(1---X,Y), loc.start and loc.end( coordinate), num.mark and seg
> mean. I would like to create the same file ( with 6 columns) but only
> containing information from chromosome 1, then another one for 2 then
> 3...Y. Could somebody help please?
>  > sessionInfo()
> R version 2.11.1 (2010-05-31)
> x86_64-unknown-linux-gnu
>
> locale:
> [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
> [3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
> [5] LC_MONETARY=C LC_MESSAGES=C
> [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
> [9] LC_ADDRESS=C LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] tools stats graphics grDevices utils datasets methods
> [8] base
>
> other attached packages:
> [1] cghMCR_1.8.0 limma_3.4.3 CNTools_1.6.0 genefilter_1.32.0
> [5] DNAcopy_1.24.0
>
> loaded via a namespace (and not attached):
> [1] annotate_1.26.0 AnnotationDbi_1.10.1 Biobase_2.8.0
> [4] DBI_0.2-5 RSQLite_0.9-1 splines_2.11.1
> [7] survival_2.35-8 xtable_1.5-6
>
> thanks a lot
> Nathalie
>
>
> ID 	chrom 	loc.start 	loc.end 	num.mark 	seg.mean
> 1 	X10Th.txt 	1 	3002738 	4.2E+07 	3202 	-0.0163
> 2 	X10Th.txt 	1 	4.2E+07 	4.2E+07 	2 	-0.7027
> 3 	X10Th.txt 	1 	4.2E+07 	1.7E+08 	10731 	0.0081
> 4 	X10Th.txt 	1 	1.7E+08 	1.7E+08 	11 	0.7461
> 5 	X10Th.txt 	1 	1.7E+08 	2.0E+08 	2448 	-0.0052
> 6 	X10Th.txt 	10 	3002742 	1.3E+08 	11833 	-0.0574
> 7 	X10Th.txt 	11 	3026911 	3100146 	12 	-0.4499
> 8 	X10Th.txt 	11 	3102021 	3.4E+07 	2516 	0.007
> 9 	X10Th.txt 	11 	3.4E+07 	3.4E+07 	4 	0.7885
> 10 	X10Th.txt 	11 	3.4E+07 	7.1E+07 	3834 	-0.0119
> 11 	X10Th.txt 	11 	7.1E+07 	7.1E+07 	10 	-1.5455
> 12 	X10Th.txt 	11 	7.1E+07 	8.3E+07 	1618 	0.0099
> 13 	X10Th.txt 	11 	8.3E+07 	8.4E+07 	2 	-1.9797
> 14 	X10Th.txt 	11 	8.4E+07 	9.0E+07 	739 	0.0197
> 15 	X10Th.txt 	11 	9.0E+07 	9.0E+07 	3 	0.4815
> 16 	X10Th.txt 	11 	9.0E+07 	1.2E+08 	3920 	-0.0171
> 17 	X10Th.txt 	12 	3095298 	6.3E+07 	4424 	0.0474
> 18 	X10Th.txt 	12 	6.3E+07 	6.3E+07 	3 	0.5165
> 19 	X10Th.txt 	12 	6.3E+07 	1.1E+08 	5209 	0.0385
> 20 	X10Th.txt 	12 	1.1E+08 	1.1E+08 	6 	-0.4526
> 21 	X10Th.txt 	12 	1.1E+08 	1.2E+08 	201 	0.1305
> 22 	X10Th.txt 	12 	1.2E+08 	1.2E+08 	19 	0.614
> 23 	X10Th.txt 	12 	1.2E+08 	1.2E+08 	481 	0.0334
> 24 	X10Th.txt 	13 	3004789 	1.2E+08 	10642 	-0.3045
> 25 	X10Th.txt 	14 	3892581 	5.2E+07 	4281 	0.5563
> 26 	X10Th.txt 	14 	5.2E+07 	5.2E+07 	4 	-0.4408
> 27 	X10Th.txt 	14 	5.2E+07 	5.2E+07 	11 	-1.4074
> 28 	X10Th.txt 	14 	5.2E+07 	5.3E+07 	12 	-0.6649
> 29 	X10Th.txt 	14 	5.3E+07 	5.3E+07 	18 	-1.5591
> 30 	X10Th.txt 	14 	5.3E+07 	5.3E+07 	56 	-2.6024
> 31 	X10Th.txt 	14 	5.3E+07 	6.8E+07 	1815 	0.5608
> 32 	X10Th.txt 	14 	6.8E+07 	6.8E+07 	33 	0.1478
> 33 	X10Th.txt 	14 	6.8E+07 	1.2E+08 	4457 	0.5724
> 34 	X10Th.txt 	15 	3091692 	3.9E+07 	2821 	0.6079
> 35 	X10Th.txt 	15 	3.9E+07 	3.9E+07 	5 	0.1051
> 36 	X10Th.txt 	15 	3.9E+07 	3.9E+07 	12 	0.5436
> 37 	X10Th.txt 	15 	3.9E+07 	3.9E+07 	2 	-0.8667
> 38 	X10Th.txt 	15 	3.9E+07 	1.0E+08 	6464 	0.6688
> 39 	X10Th.txt 	16 	3151162 	6024268 	339 	-0.1676
> 40 	X10Th.txt 	16 	6032525 	6045766 	3 	-2.3133
> 41 	X10Th.txt 	16 	6056091 	3.6E+07 	3366 	-0.136
> 42 	X10Th.txt 	16 	3.6E+07 	3.6E+07 	4 	-1.392
> 43 	X10Th.txt 	16 	3.6E+07 	9.8E+07 	5329 	-0.1383
> 44 	X10Th.txt 	17 	3009074 	9.5E+07 	9007 	-0.1542
> 45 	X10Th.txt 	18 	3181133 	9.1E+07 	8058 	-0.0622
> 46 	X10Th.txt 	19 	3147156 	1.7E+07 	1848 	-0.3487
> 47 	X10Th.txt 	19 	1.7E+07 	1.8E+07 	100 	-0.9124
> 48 	X10Th.txt 	19 	1.8E+07 	6.1E+07 	4443 	-0.3708
> 49 	X10Th.txt 	2 	3010301 	3.1E+07 	2777 	0.1381
> 50 	X10Th.txt 	2 	3.1E+07 	3.1E+07 	4 	-0.3156
> 51 	X10Th.txt 	2 	3.1E+07 	7.2E+07 	3546 	0.1484
> 52 	X10Th.txt 	2 	7.2E+07 	7.2E+07 	2 	-0.4492
> 53 	X10Th.txt 	2 	7.2E+07 	9.0E+07 	1994 	0.1389
> 54 	X10Th.txt 	2 	9.0E+07 	9.0E+07 	2 	0.7181
> 55 	X10Th.txt 	2 	9.0E+07 	9.1E+07 	192 	0.1815
> 56 	X10Th.txt 	2 	9.1E+07 	9.1E+07 	4 	0.6128
> 57 	X10Th.txt 	2 	9.1E+07 	1.8E+08 	8335 	0.1312
> 58 	X10Th.txt 	3 	3007185 	1.4E+08 	11302 	-0.1118
> 59 	X10Th.txt 	3 	1.4E+08 	1.4E+08 	3 	1.1729
> 60 	X10Th.txt 	3 	1.4E+08 	1.6E+08 	1828 	-0.1205
> 61 	X10Th.txt 	4 	3012291 	3335299 	10 	0.0708
> 62 	X10Th.txt 	4 	3353037 	9459467 	498 	0.6502
> 63 	X10Th.txt 	4 	9469402 	9469402 	3 	-0.1167
> 64 	X10Th.txt 	4 	9473906 	1.1E+07 	123 	0.8942
> 65 	X10Th.txt 	4 	1.1E+07 	1.4E+07 	253 	0.334
> 66 	X10Th.txt 	4 	1.5E+07 	1.6E+07 	150 	0.8265
> 67 	X10Th.txt 	4 	1.6E+07 	1.9E+07 	179 	0.322
> 68 	X10Th.txt 	4 	1.9E+07 	2.5E+07 	463 	0.8283
> 69 	X10Th.txt 	4 	2.5E+07 	2.5E+07 	2 	-4.1559
> 70 	X10Th.txt 	4 	2.5E+07 	3.7E+07 	759 	0.8149
> 71 	X10Th.txt 	4 	3.7E+07 	3.7E+07 	20 	1.2765
> 72 	X10Th.txt 	4 	3.7E+07 	5.9E+07 	1833 	0.4829
> 73 	X10Th.txt 	4 	5.9E+07 	6E+07 	83 	1.0287
> 74 	X10Th.txt 	4 	6.0E+07 	6.6E+07 	455 	0.623
> 75 	X10Th.txt 	4 	6.6E+07 	6.6E+07 	3 	-4.8121
> 76 	X10Th.txt 	4 	6.6E+07 	8.7E+07 	1509 	0.4519
> 77 	X10Th.txt 	4 	8.7E+07 	8.8E+07 	37 	0.9291
> 78 	X10Th.txt 	4 	8.8E+07 	9.7E+07 	764 	0.3171
> 79 	X10Th.txt 	4 	9.7E+07 	1.0E+08 	417 	0.8177
> 80 	X10Th.txt 	4 	1.0E+08 	1.0E+08 	35 	1.3066
> 81 	X10Th.txt 	4 	1.0E+08 	1.1E+08 	1125 	0.7607
> 82 	X10Th.txt 	4 	1.1E+08 	1.2E+08 	933 	0.3508
> 83 	X10Th.txt 	4 	1.2E+08 	1.2E+08 	192 	0.8091
> 84 	X10Th.txt 	4 	1.2E+08 	1.2E+08 	15 	1.3286
> 85 	X10Th.txt 	4 	1.2E+08 	1.2E+08 	78 	0.8328
> 86 	X10Th.txt 	4 	1.2E+08 	1.4E+08 	1514 	0.3228
> 87 	X10Th.txt 	4 	1.4E+08 	1.4E+08 	3 	1.2655
> 88 	X10Th.txt 	4 	1.4E+08 	1.5E+08 	1352 	0.283
> 89 	X10Th.txt 	4 	1.5E+08 	1.5E+08 	41 	0.8091
> 90 	X10Th.txt 	4 	1.5E+08 	1.6E+08 	793 	0.2844
> 91 	X10Th.txt 	5 	3003879 	3.3E+07 	2707 	0.105
> 92 	X10Th.txt 	5 	3.3E+07 	3.3E+07 	3 	-0.6753
> 93 	X10Th.txt 	5 	3.3E+07 	9.4E+07 	5039 	0.1072
> 94 	X10Th.txt 	5 	9.4E+07 	9.6E+07 	8 	-0.8031
> 95 	X10Th.txt 	5 	9.6E+07 	1.5E+08 	6236 	0.1028
> 96 	X10Th.txt 	6 	3024849 	2.6E+07 	1843 	-0.1733
> 97 	X10Th.txt 	6 	2.6E+07 	2.6E+07 	2 	-0.773
> 98 	X10Th.txt 	6 	2.6E+07 	3.4E+07 	864 	-0.1393
> 99 	X10Th.txt 	6 	3.4E+07 	3.4E+07 	3 	-2.5977
> 100 	X10Th.txt 	6 	3.4E+07 	4.1E+07 	744 	-0.1363
> 101 	X10Th.txt 	6 	4.1E+07 	4.1E+07 	60 	-0.9053
> 102 	X10Th.txt 	6 	4.1E+07 	1.2E+08 	7693 	-0.1561
> 103 	X10Th.txt 	6 	1.2E+08 	1.2E+08 	2 	0.5483
> 104 	X10Th.txt 	6 	1.2E+08 	1.5E+08 	2924 	-0.1333
> 105 	X10Th.txt 	7 	3049177 	2.9E+07 	2215 	-0.174
> 106 	X10Th.txt 	7 	2.9E+07 	2.9E+07 	3 	-0.8632
> 107 	X10Th.txt 	7 	2.9E+07 	3.4E+07 	496 	-0.1613
> 108 	X10Th.txt 	7 	3.4E+07 	3.5E+07 	55 	-0.6911
> 109 	X10Th.txt 	7 	3.5E+07 	1.0E+08 	6236 	-0.1745
> 110 	X10Th.txt 	7 	1.0E+08 	1.0E+08 	5 	-1.4229
> 111 	X10Th.txt 	7 	1.0E+08 	1.0E+08 	20 	-0.1964
> 112 	X10Th.txt 	7 	1.0E+08 	1.0E+08 	6 	-1.8286
> 113 	X10Th.txt 	7 	1.0E+08 	1.5E+08 	4582 	-0.1627
> 114 	X10Th.txt 	8 	3111085 	1.3E+08 	11524 	-0.1437
> 115 	X10Th.txt 	9 	3088282 	1.2E+08 	12045 	0.2501
> 116 	X10Th.txt 	X 	3086068 	1.7E+08 	12085 	-0.0107
> 117 	X10Th.txt 	Y 	27 	263780 	52 	-1.2383
> 118 	X10Th.txt 	Y 	263932 	631098 	15 	-0.5181
> 119 	X10Th.txt 	Y 	631698 	2177516 	532 	-1.256
> 120 	X11Th.txt 	1 	3002738 	2.0E+08 	16394 	-0.046
> 121 	X11Th.txt 	10 	3002742 	2.2E+07 	1710 	-0.2582
> 122 	X11Th.txt 	10 	2.2E+07 	2.2E+07 	2 	-2.3611
> 123 	X11Th.txt 	10 	2.2E+07 	1.3E+08 	10121 	-0.2586
> 124 	X11Th.txt 	11 	3026911 	3.4E+07 	2528 	-0.049
> 125 	X11Th.txt 	11 	3.4E+07 	3.4E+07 	5 	1.0058
> 126 	X11Th.txt 	11 	3.4E+07 	1.2E+08 	10125 	-0.035
> 127 	X11Th.txt 	12 	3095298 	6.3E+07 	4424 	-0.0904
> 128 	X11Th.txt 	12 	6.3E+07 	6.3E+07 	3 	1.7028
> 129 	X11Th.txt 	12 	6.3E+07 	1.2E+08 	5916 	-0.0654
> 130 	X11Th.txt 	13 	3004789 	1.3E+07 	854 	-0.1304
> 131 	X11Th.txt 	13 	1.3E+07 	1.3E+07 	5 	-1.3861
> 132 	X11Th.txt 	13 	1.3E+07 	2.8E+07 	1591 	-0.1782
> 133 	X11Th.txt 	13 	2.8E+07 	2.8E+07 	5 	-1.3185
> 134 	X11Th.txt 	13 	2.8E+07 	6.5E+07 	3634 	-0.1527
> 135 	X11Th.txt 	13 	6.6E+07 	6.7E+07 	8 	-1.1874
> 136 	X11Th.txt 	13 	6.7E+07 	6.9E+07 	201 	-0.1626
> 137 	X11Th.txt 	13 	6.9E+07 	6.9E+07 	4 	1.0844
> 138 	X11Th.txt 	13 	6.9E+07 	1.2E+08 	4340 	-0.1625
> 139 	X11Th.txt 	14 	3892581 	5.3E+07 	4319 	0.6606
> 140 	X11Th.txt 	14 	5.3E+07 	5.3E+07 	58 	-1.4906
> 141 	X11Th.txt 	14 	5.3E+07 	1.2E+08 	6310 	0.6554
> 142 	X11Th.txt 	15 	3091692 	8039326 	448 	0.4734
> 143 	X11Th.txt 	15 	8040778 	8040778 	3 	1.6185
> 144 	X11Th.txt 	15 	8046698 	3.9E+07 	2358 	0.454
> 145 	X11Th.txt 	15 	3.9E+07 	3.9E+07 	3 	1.5325
> 146 	X11Th.txt 	15 	3.9E+07 	1.0E+08 	6492 	0.4605
> 147 	X11Th.txt 	16 	3151162 	9.8E+07 	9041 	-0.2314
> 148 	X11Th.txt 	17 	3009074 	9.5E+07 	9007 	-0.0573
> 149 	X11Th.txt 	18 	3181133 	9.1E+07 	8058 	0.0341
> 150 	X11Th.txt 	19 	3147156 	6.1E+07 	6391 	-0.1194
> 151 	X11Th.txt 	2 	3010301 	5.0E+07 	4560 	0.1442
> 152 	X11Th.txt 	2 	5.0E+07 	5.0E+07 	4 	1.1306
> 153 	X11Th.txt 	2 	5.0E+07 	1.8E+08 	12292 	0.1487
> 154 	X11Th.txt 	3 	3007185 	6032558 	245 	-0.2823
> 155 	X11Th.txt 	3 	6056822 	6072724 	3 	1.2882
> 156 	X11Th.txt 	3 	6083291 	1.6E+08 	12885 	-0.2812
> 157 	X11Th.txt 	4 	3012291 	3146483 	5 	-0.8101
> 158 	X11Th.txt 	4 	3159538 	1.6E+08 	13637 	0.2846
> 159 	X11Th.txt 	5 	3003879 	1.1E+07 	656 	0.0416
>
>
>
>
>
> --
>  The Wellcome Trust Sanger Institute is operated by Genome Research
>  Limited, a charity registered in England with number 1021457 and a
>  company registered in England with number 2742969, whose registered
>  office is 215 Euston Road, London, NW1 2BE.
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor



More information about the Bioconductor mailing list