mercredi 12 août 2020

Finding exact row used in sapply

I would like to be able to see whether values in a column of a data frame are within the range of values in another dataframe. I can do that with sapply and put Yes and NA with ifelse. However, I want to be able to find out exactly which row numbers of the first file was used for those Yes rows or the contents of second df matched which columns and get the contents of that column.

This is what I am using: cigar2_count$Visit1_counts <- ifelse(sapply(cigar2_count$HPV_Position, function(p) any(cigar1_count$minV <= p & cigar1_count$maxV >= p)),"YES", NA)

This is what I want to be able to do; cigar2_count$Visit1_counts <- ifelse(sapply(cigar2_count$HPV_Position, function(p) any(cigar1_count$minV <= p & cigar1_count$maxV >= p)),cigar1_count$Unique_Read_Count, NA)

Thanks!

Aucun commentaire:

Enregistrer un commentaire