0

I'd like to retain rows with only one element and I am struggling to find a code/package that allows me to do that.

to be clearer, this is an example of my dataset:

Dataset extract

Considering variable A1, I would like to remove row 5 as it has two elements (CA) and considering variable A2, rows 16 (TAA) and 19 (GA) should be removed. I tried to use the "str_remove" command but the cells with two or more elements are all different in terms of letters they include as well as number of elements in them (e.g, one cell can have two elements and others have even 5 elements in it), so I cannot establish a pattern.

Do you have any suggestion? Thanks for your help

Silvia

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
  • 2
    hi PsychSilvia. Welcome to StackOverflow! Please do not post images of code or data here. Instead read the info about [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and how to give a [minimale reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610).That way you can help others to help you! – dario Feb 17 '20 at 13:06
  • Hi Dario! thank you for these info, I wasn't sure I was doing it right. I'll be more careful next time! – PsychSilvia Feb 17 '20 at 16:40

1 Answers1

0
df[apply(apply(df[,c("A1","A2"),drop=F],2,nchar),1,max)==1,]

where you can replace c("A1","A2") with your vector of columns.

user2974951
  • 9,535
  • 1
  • 17
  • 24