Selecting specific rows in r based on condition -



Selecting specific rows in r based on condition -

i have table in r called "tc" contains various info shown below:

tc[1:5,] tfirst tsecond type 1 2013-05-21 23:19:56 2013-05-22 13:33:12 2 2 2013-05-22 13:33:12 2013-05-22 14:29:44 1 3 2013-05-22 14:29:44 2013-05-22 17:02:18 2 4 2013-05-22 17:02:18 2013-05-22 17:13:29 1 5 2013-05-22 17:13:29 2013-05-22 19:42:14 2

i have dataset in r called "df" thta contains either true or false same rows in tc, shown below:

df [1] false true false true true

how can apply df in creating new table tc, let's phone call newtc, rows associated true appear? expected output using examples newtc be:

newtc tfirst tsecond type 2 2013-05-22 13:33:12 2013-05-22 14:29:44 1 4 2013-05-22 17:02:18 2013-05-22 17:13:29 1 5 2013-05-22 17:13:29 2013-05-22 19:42:14 2

tc , df contain 700 rows, these examples portions.

to subset rows of tc true values of vector df, can do

tc[df,]

here's how i'm presuming info set up, based on examples:

> tc <- read.table(h=t, text = "tfirst tsecond type 1 '2013-05-21 23:19:56' '2013-05-22 13:33:12' 2 2 '2013-05-22 13:33:12' '2013-05-22 14:29:44' 1 3 '2013-05-22 14:29:44' '2013-05-22 17:02:18' 2 4 '2013-05-22 17:02:18' '2013-05-22 17:13:29' 1 5 '2013-05-22 17:13:29' '2013-05-22 19:42:14' 2") > df <- c(false, true, false, true, true) > tc[df,] # tfirst tsecond type # 2 2013-05-22 13:33:12 2013-05-22 14:29:44 1 # 4 2013-05-22 17:02:18 2013-05-22 17:13:29 1 # 5 2013-05-22 17:13:29 2013-05-22 19:42:14 2

r

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -