Rearranging data frame based on column values
0
0
Entering edit mode
22 months ago
Paula ▴ 60

Hi!

I have a table with different categories and the respective coverage values:

taxonomy coverage
A 20
ADK 6
ADL 3

Now, I want to separate the taxonomy categories into categories of individual letters. I need to assign the coverage value to the new categories of individual letters. The criteria are the following:

The coverage value for categories with 3 letters will be divided by 3 and 1/3 of the value will be assigned to each individual category.

Here is what the table should look like at the end:

taxonomy coverage
A 23
D 3
K 2
L 1

Thanks a lot!

python biopython • 553 views
ADD COMMENT
2
Entering edit mode

In case you don't realize it, what you are doing is an equivalent of saying Here is what I need, go fetch!. You are laying out your expectations without showing the slightest effort to solve the problem. There may be a good soul on this forum who will still do this for you, but that's not a way to go about it.

Out of curiosity, why biopython in keywords?

ADD REPLY
0
Entering edit mode

R:

> df %>% 
+   mutate(v3=nchar(V1)) %>% 
+   separate_rows (V1,sep ="") %>% 
+   na_if("") %>%
+   na.omit %>% 
+   mutate (counts=V2/v3) %>% 
+   group_by(V1) %>% 
+   mutate(count_sum=sum(counts)) %>% 
+   select(V1,count_sum) %>% 
+   distinct()

# A tibble: 4 × 2
# Groups:   V1 [4]
  V1    count_sum
  <chr>     <dbl>
1 A            23
2 D             3
3 K             2
4 L             1
ADD REPLY

Login before adding your answer.

Traffic: 1815 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6