Can observations in R be removed along with subsequent data in its row through the use of subset? -


here example of data frame i'm working on [the data frame (189x11)]:

   >wb        id age lwt race smoke ptl ht ui fvt  bwt low        85  19 182    2     0   0  0  1   0 2523   0        86  33 155    3     0   0  0  0   3 2551   0        87  20 105    1     1   0  0  0   1 2557   0        88  21 108    1     1   0  0  1   2 2594   0 

now through use of subset want create subsettted dataframe contain table women whom smoked during pregnancy , vice versa, want this:

      >smoke         id age lwt race smoke ptl ht ui fvt  bwt low        87  20 105    1     1   0  0  0   1 2557   0        88  21 108    1     1   0  0  1   2 2594   0 

and

       >nonsmoke        id age lwt race smoke ptl ht ui fvt  bwt low        85  19 182    2     0   0  0  1   0 2523   0        86  33 155    3     0   0  0  0   3 2551   0 

however, when use subset:

    smoke <-subset(dategrame,smoke==1) 

i this:

      id age lwt race smoke ptl ht ui fvt  bwt low        85  19 182    2     1   0  0  1   0 2523   0        86  33 155    3     1   0  0  0   3 2551   0        87  20 105    1     1   0  0  0   1 2557   0        88  21 108    1     1   0  0  1   2 2594   0 

so me understand i'm doing wrong , why can't dataframes want? because i'm trying separate them can compare bwt of mothers whom smoked , didn't smoke through boxplot.

there no need subset dataframe if want make boxplot plot that. try this:

d = data.frame(smoke=c(0,0,0,1,1,1), bwt=c(2523,2551,2560,2557,2594,2600)) boxplot(d$bwt ~ d$smoke) 

enter image description here


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -