Skip to content

How to extract range of colums in a data frame

4 messages · Gundala Viswanath, Jorge Ivan Velez, stephen sefick +1 more

#
Dear all,

I have the following data frame:
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
#
x <- dat[,3:9]
# I think this is what you want.

On Sun, Jan 4, 2009 at 9:42 PM, Jorge Ivan Velez
<jorgeivanvelez at gmail.com> wrote:

  
    
#
Or this:

new.DF <- subset(dat, select = V3:V9)
'data.frame':	16 obs. of  7 variables:
 $ V3: num  9 18 15 15 21 21 12 15 21 19.5 ...
 $ V4: int  18 8 8 6 21 21 21 9 21 18 ...
 $ V5: num  12 12 12 18 21 ...
 $ V6: num  18 18 12 6 21 21 21 18 21 19.5 ...
 $ V7: num  15 15 18 18 21 21 21 15 21 16.5 ...
 $ V8: num  12 12 12 15 21 21 21 15 21 19.5 ...
 $ V9: num  6 18 12 9 21 21 21 6 21 18 ...


See ?subset for the above and ?"[.data.frame" for additional information
on subsetting data frames, which is also covered in An Introduction to R.

HTH,

Marc Schwartz
on 01/04/2009 08:42 PM Jorge Ivan Velez wrote: