-1

I need to select the exact rows from the old data frame and create a new one. I need to choose rows which contain paired numbers (as 11, 22, 33, 44, 55, 66, 77, 88 and 99). How can I do this?

I tried using filter:

paired1 <- filter(paired1$Var1=='22')
# Error in UseMethod("filter") : 
#  no applicable method for 'filter' applied to an object of class "logical"

And with:

> with (paired1, sum (Freq[Var1 == '11' & '22']))
# Error in Var1 == "11" & "22" : 
#  operations are possible only for numeric, logical or complex types
Ric
  • 5,362
  • 1
  • 10
  • 23
anastasiia
  • 13
  • 1
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. It should look more like `paired1 <- filter(paired1, Var1=='22')` assuming you are using `dplyr::filter` – MrFlick Jan 06 '23 at 21:20
  • You need `with(paired1, sum(Freq[Var1 %in% c(11, 22)]))` – akrun Jan 06 '23 at 21:22

2 Answers2

0

For two digit numbers:

paired1[paired1$var1 %in% seq(11, 99, 11),]
Ric
  • 5,362
  • 1
  • 10
  • 23
0

We may use

subset(paired1, !nchar(sub("(\\d)\\1+", "", var1)))

-output

  var1
4   99
5   11
7   44
8  777
9  555

data

 paired1 <- data.frame(var1 = c(12, 13, 25, 99, 11, 42, 44, 777, 555, 3))
akrun
  • 874,273
  • 37
  • 540
  • 662