indexing using character vectors

r

Solution

`==` will do element by element checking of equality. Vector recycling comes into play here; it will check the first element of primer against the first element of ges, the second element of primer against the second element of ges, the third element of primer against the first element of ges (due to the recycling) and so on and so forth. What you actually want is to use the `%in%` operator to check if the elements of primer are in the vector ges.

df[df$primer %in% ges,]

Problem

df ``` primer exptname concentrate timepoints replicate day realConc Acan 0hr 55mM 0 b1 011311 0.0002771494 Actb 0hr 55mM 0 b1 011311 0.0061298654 Atf7ip2 0hr 55mM 0 b1 011311 0.0015750373 Atp2c1 0hr 55mM 0 b1 011311 0.0010109867 Casp6 0hr 55mM 0 b1 011311 0.0035939088 Col10a1 0hr 55mM 0 b1 011311 0.0133760938 Acan 0hr 55mM 0 b1 011311 0.0002771494 Actb 0hr 55mM 0 b1 011311 0.0061298654 Atf7ip2 0hr 55mM 0 b1 011311 0.0015750373 Atp2c1 0hr 55mM 0 b1 011311 0.0010109867 Casp6 0hr 55mM 0 b1 011311 0.0035939088 Col10a1 0hr 55mM 0 b1 011311 0.0133760938 ``` i Have character vector: ``` ges <- c('Acan','Casp6') ``` I only want rows where $primer == ges I've tried ``` df[df$primer == ges,] ``` but it only returns the first rows which equals these two characters as opposed to all rows in the data frame which equal this I feel like this is ridiculously simple but I'm messing up somewhere basic Help a brother out

Original source