[R] How to extract range of colums in a data frame

Gundala Viswanath gundalav at gmail.com
Mon Jan 5 03:36:04 CET 2009


Dear all,

I have the following data frame:

> dat
   V1                                 V2   V3 V4    V5   V6   V7   V8   V9
1   1 AAAACACCCACCCCCCCCCCCCCCCCCCCCCCCC  9.0 18 12.00 18.0 15.0 12.0  6.0
2   1 ACGATACGGCGACCACCGAGATCTACACTCTTCC 18.0  8 12.00 18.0 15.0 12.0 18.0
3   1 ACTACTGCTCCCCCCCCACTCCCCCCCCCCCCCC 15.0  8 12.00 12.0 18.0 12.0 12.0
4   1 ACTTATACGGCGACCACCGAGATCTACACTCTTT 15.0  6 18.00  6.0 18.0 15.0  9.0
5   1 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 21.0 21 21.00 21.0 21.0 21.0 21.0
6   1 CTACACTCTTTCCCTACACGCCGCTCTTCCGATC 21.0 21 21.00 21.0 21.0 21.0 21.0
7   1 TACACCGCCCCCCCCCATCTCCACACTCTCCCCC 12.0 21 12.00 21.0 21.0 21.0 21.0
8   1 TGATACGCCTACCACCGCCCTCTACACTCTCTCC 15.0  9 18.00 18.0 15.0 15.0  6.0
9   1 TGATACGGCGACCACCGAGATCTACACTCTCTCC 21.0 21 21.00 21.0 21.0 21.0 21.0
10  4 TGATACGGCGACCACCGAGATCTACACTCTTTCC 19.5 18 15.75 19.5 16.5 19.5 18.0
11  1 TGATACGGCGACCACCGAGGATCTACACTCTTTC 21.0 21 21.00 21.0 21.0 21.0 21.0
12  1 TGATACGGCGACCACCGAGGATCTCCACTCTCTC 21.0 21 21.00 21.0 21.0 21.0 21.0
13  2 TGCTCCGGCGACCACCGAGATCTACACTCTTTCC 18.0  8 12.00 18.0 13.5 18.0 13.5
14  1 TTATACGTCGACCACCGAGATCTACACTCTCTCC 18.0 18 18.00 18.0 18.0 18.0 15.0
15  1 TTCTCCGGCGACCACCGAGATCTACACTCTTTCC 18.0  7  9.00 18.0 12.0 18.0 15.0
16  1 TTCTCCGGCGACCACCGCGATCTACACTCTTTCC 18.0  7  9.00 18.0 12.0 18.0 15.0


My question is how can I extract the column V3 up to V9 into another
new data frame.

I tried this but failed:
str <- paste("V", 3:9, sep="")
print(dat$str)




- Gundala Viswanath
Jakarta - Indonesia




More information about the R-help mailing list