0

I've been searching for a way to take 2 columns from a table that I uploaded from excel to R and basically make another table with the same number of rows. The original table has 222 rows (each row represents a participant) and of this table I want to take two columns to make this new table that will have the same amount of rows so I can then omit the NA values in these two columns. I've tried this code, but I get this result.

ep_public1=table(SCRAM$ep_public,SCRAM$bl_sex)
      1  2
  0   2 12
  1  23 60
  2  13 19
  3  20 31
  4  23 17
  NA  0  2

The ep_public variable ranges from 0 to 4, and has a NA response (after I create the new table I wish to omit or eliminate the 2 participants that did not respond). The bl_sex is just 1 or 2. Is there a way for me to do this? Thanks ahead!

Owslad
  • 15
  • 2
  • 1
    In order to give a [good reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), it's helpful to provide some of your data, which you can do using `dput(head())`. Then, edit your question and include the `dput` output. – AndrewGB Jul 01 '21 at 23:48

2 Answers2

0

Depending on your data structure, you can potentially do something like this

ep_public1 <- SCRAM[ , c("ep_public", "bl_sex") ]
akrun
  • 874,273
  • 37
  • 540
  • 662
AndrewGB
  • 16,126
  • 5
  • 18
  • 49
0

table function should by default drop NA values. I think you might have character "NA" values. (What is class(SCRAM$ep_public) ?) Try replacing them with real NA and then use table.

SCRAM[SCRAM == 'NA'] <- NA
ep_public1 = table(SCRAM$ep_public,SCRAM$bl_sex)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213