[R] How To Extract Row from A Data Frame

jim holtman jholtman at gmail.com
Mon Oct 4 04:30:56 CEST 2010


?subset

> x
  V2     V3     V4     V5     V6     V7     V8     V9    V10    V11    V12
1 FN  8.637 28.890 31.430 31.052 29.878 33.215 32.728 32.187 29.305 31.462
2 FP 19.936 30.284 33.001 35.100 30.238 34.452 35.849 34.185 31.242 35.635
3 TN  0.000 17.190 16.460 21.100 17.960 15.120 17.200 17.190 15.270 15.310
4 TP 22.831 31.246 33.600 35.439 32.073 33.947 35.050 34.472 31.228 33.701
> subset(x, select = V3:V12)
      V3     V4     V5     V6     V7     V8     V9    V10    V11    V12
1  8.637 28.890 31.430 31.052 29.878 33.215 32.728 32.187 29.305 31.462
2 19.936 30.284 33.001 35.100 30.238 34.452 35.849 34.185 31.242 35.635
3  0.000 17.190 16.460 21.100 17.960 15.120 17.200 17.190 15.270 15.310
4 22.831 31.246 33.600 35.439 32.073 33.947 35.050 34.472 31.228 33.701
>


On Sun, Oct 3, 2010 at 10:22 PM, Gundala Viswanath <gundalav at gmail.com> wrote:
> I have a data frame that looks like this:
>
>
>> print(df)
>  V2     V3     V4     V5     V6     V7     V8     V9    V10    V11    V12
> 1 FN  8.637 28.890 31.430 31.052 29.878 33.215 32.728 32.187 29.305 31.462
> 2 FP 19.936 30.284 33.001 35.100 30.238 34.452 35.849 34.185 31.242 35.635
> 3 TN  0.000 17.190 16.460 21.100 17.960 15.120 17.200 17.190 15.270 15.310
> 4 TP 22.831 31.246 33.600 35.439 32.073 33.947 35.050 34.472 31.228 33.701
>
>
> How can I extract rows as specified, e.g.
> I tried this to extract the first line ("FN") starting from V3 to V12:
>
>> fn <- df[1,df$V3:df$V12]
>
> But it gives columns starting not from V3.
>
> What's the right way to do it?
>
> - G.V.
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list