Subsetting my data- Pls help this poor grad student!!

Hello anyone that can help,

I'm working on the Correlates of War (Interstate Dispute MIDB V4.3) dataset, all I need to do is pull four country codes from the V3 column and have those countries configured as their own data frame along with all the existing rows (V1-V19). someone pls help me.

Because this column is a factor variable, and I'm pulling four of them from the column I'm finding it hard to find an example of the code I would need. Thanks in advance!!

I would recommend studying section 5.2, about the filter function of dplyr/tidyverse

hello, thank you for the reply. That textbook is very useful, thanks for sharing. I installed both "tinyverse" and "dplyr" , and tried using the filter command and it was still unable to return anything for me.

I know this step is not difficult and I'm much more proficient in R than this, but it's stumping me :frowning:

here's the code I've tried so far:

filter(MIDB.4.3, V4 = 750)
Error in filter(MIDB.4.3, V4 = 750) : unused argument (V4 = 750)

filter(MIDB.4.3, ccode = 750)
Error in filter(MIDB.4.3, ccode = 750) : unused argument (ccode = 750)
filter(MIDB.4.3, ccode == 750)
Error in filter(MIDB.4.3, ccode == 750) : object 'ccode' not found
filter(MIDB.4.3, V4 == 750)
Error in filter(MIDB.4.3, V4 == 750) : object 'V4' not found
india <- filter(MIDB.4.3, V4 == 750)
Error in filter(MIDB.4.3, V4 == 750) : object 'V4' not found

I'm confused because you said you would pull country codes from a V3 column, and then your examples show selection , on a V4 ?
if whichever column you want to filter by is a factor then when you type out the value to be matched you would wrap it in quotes

filter(MIDB.4.3, V4 = '750')

That doesn't seem to be the error message that you'd get from mistakenly using a single = in the dplyr filter function, at least not any recent version of it.

If you have dplyr installed, is it possible that you're forgetting to load it?

library(dplyr)

What you can do is try:

dplyr::filter(MIDB.4.3, V4 == 750) #two equal signs

That ensures that you're using the dplyr function filter and not the function with the same name from stats.

1 Like

Both V3 and V4 columns represent the same information,

V3: country name abbreviation
V4: country code number (pre-assigned in the codebook)

:slight_smile:

Thank you so much- this was the issue!!!

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.