Bonjour,
J'aimerai appliquer une série d'action sur plusieurs colonnes d'un tableau dont vous avez les premières lignes ci dessous mais j'ai du mal à utiliser le système de fonction, si quelqu'un voulait bien m'aiguiller.
La série d'action à réalisé est toute simple (et pourrait également être simplifié grâce à vos différents conseils). J'aimerai pour chaque colonne calculer le % de catégorie sachant que certaines cases sont vide. Ci dessous mes lignes de code appliquées à une colonneCode:
1
2
3
4
5
6
7
8 verification1 vérification2 verification3 verification4 verification5 1 <NA> <NA> <NA> <NA> Absent 2 <NA> <NA> DeNovo <NA> DeNovo 3 <NA> <NA> <NA> <NA> DeNovo 4 <NA> <NA> <NA> <NA> Absent 5 <NA> <NA> Paternal_Inheritance <NA> DeNovo 6 DeNovo <NA> DeNovo <NA> DeNovo
J'ai essayé d'écrire une fonction pour ensuite l'appliquer à la fonction apply mais je ne sais pas comment gérer les sorties... Jai essayé comme cela, mais ça ne me donne aucune sortie...Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 DeNovo_1=sum(tab$Variant_Type=="SNV" & tab2$verification1=="DeNovo") Uncertain_1_SNV=sum(tab$Variant_Type=="SNV" & tab2$verification1=="Uncertain") Absent_1_SNV=sum(tab$Variant_Type=="SNV" & tab2$verification1=="Absent") Maternal_1_SNV=sum(tab$Variant_Type=="SNV" & tab2$verification1=="Maternal_Inheritance") Paternal_1_SNV=sum(tab$Variant_Type=="SNV" & tab2$verification1=="Paternal_Inheritance") DeNovo_1 Absent_1 Uncertain_1 Maternal_1 Paternal_1 Done_1= DeNovo_1 + Absent_1 + Uncertain_1 + Maternal_1 + Paternal_1 pourc_DeNovo_1=DeNovo_1/Done_1 * 100 pourc_Uncertain_1=Uncertain_1/Done_1 * 100 pourc_Absent_1=Absent_1/Done_1 * 100 pourc_Maternal_1=Maternal_1/Done_1 * 100 pourc_Paternal_1=Paternal_1/Done_1 * 100
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 DeNovoPourcentage=function(x){ DeNovo_1=sum(tab$Variant_Type=="SNV" & x=="DeNovo") Uncertain_1=sum(tab$Variant_Type=="SNV" x=="Uncertain") Absent_1=sum(tab$Variant_Type=="SNV" & x=="Absent") Maternal_1=sum(tab$Variant_Type=="SNV" x=="Maternal_Inheritance") Paternal_1=sum(tab$Variant_Type=="SNV" & x=="Paternal_Inheritance") DeNovo_1 Absent_1 Uncertain_1 Maternal_1 Paternal_1 Done_1= DeNovo_1 + Absent_1 + Uncertain_1 + Maternal_1 + Paternal_1 pourc_DeNovo_1=DeNovo_1/Done_1 * 100 pourc_Uncertain_1=Uncertain_1/Done_1 * 100 pourc_Absent_1=Absent_1/Done_1 * 100 pourc_Maternal_1=Maternal_1/Done_1 * 100 pourc_Paternal_1=Paternal_1/Done_1 * 100 }
[/CODE]
J'aimerai ensuite créer un tableau résumé en fonction des % des différentes colonnes, mais comme je ne sais pas gérer les sorties avec les fonctions, j'aimerai recevoir quelques pistes.
Merci d'avance,Code:
1
2
3
4
5
6
7
8 DeNovo Uncertain Absent Paternal_Inheritance Maternal_Inheritance Nombre Verif1 76.81564 5.3072626 17.877095 0.0000000 0.000000 716 Verif2 77.45098 0.0000000 22.549020 0.0000000 0.000000 102 Verif3 90.00000 0.0000000 0.000000 0.0000000 10.000000 20 Verif4 89.70588 0.7352941 7.352941 0.0000000 2.205882 136 Verif5 21.84874 12.6050420 65.546218 0.0000000 0.000000 119 >
Aline Vitrac