0

I split a biological sample into multiple "tiles" using a program called QuPath and I'm using R to parse the data. I was hoping to divide the tiles into different buckets based on the percentage of the tile is taken up by stroma (0-10%, 10-20%, etc.). Ideally, I'd like something like the below table, but anything where I can get counts of the number of tiles that fall into the percentage "buckets" will be just fine.

Tile Percent Stroma Percent Stroma
Tile 1 5% 0-10
Tile 2 15% 10-20
Tile 3 9% 0-10
Tile 4 45% 40-50
Tile 5 61% 60-70
Tile 6 42% 40-50
Tile 7 55% 50-60

I've done something like this before with a simple ifelse function, but I'm very new to R and wanted to know if there's a more efficient way to do it.

fgootkind
  • 73
  • 6
  • You'll need to remove the percent signs and convert them to numeric to work with them, and then the `cut` function is your friend. See the two linked duplicates for those two steps. – Gregor Thomas Oct 25 '22 at 17:04
  • If you're using `library(dplyr)` and `library(readr)` you can do something like `your_data %>% mutate(stroma_numeric = parse_number(Percent_Stroma), stroma_bucket = cut(stroma_numeric, breaks = seq(0, 100, by = 10), include.lowest = TRUE))`. – Gregor Thomas Oct 25 '22 at 17:59

0 Answers0