我不確定確切的資料型別是什么,但是當我看到類時它顯示字符和數字。
我想要使??用的小子集的預期資料是這個
a <- dput(head(Age))
structure(list(Blast_Percentage = c(82L, 83L, 91L, 72L, 68L,
88L)), row.names = c("TCGA-AB-2856", "TCGA-AB-2849", "TCGA-AB-2971",
"TCGA-AB-2930", "TCGA-AB-2891", "TCGA-AB-2872"), class = "data.frame")
第二個資料框
b <- dput(head(Sample_info))
structure(list(patient = structure(c(35L, 32L, 118L, 93L, 64L,
47L), .Label = c("TCGA-AB-2805", "TCGA-AB-2806", "TCGA-AB-2808",
"TCGA-AB-2810", "TCGA-AB-2811", "TCGA-AB-2812", "TCGA-AB-2813",
"TCGA-AB-2814", "TCGA-AB-2815", "TCGA-AB-2817", "TCGA-AB-2818",
"TCGA-AB-2819", "TCGA-AB-2820", "TCGA-AB-2821", "TCGA-AB-2822",
"TCGA-AB-2823", "TCGA-AB-2825", "TCGA-AB-2826", "TCGA-AB-2828",
"TCGA-AB-2830", "TCGA-AB-2834", "TCGA-AB-2835", "TCGA-AB-2836",
"TCGA-AB-2839", "TCGA-AB-2840", "TCGA-AB-2841", "TCGA-AB-2842",
"TCGA-AB-2844", "TCGA-AB-2845", "TCGA-AB-2846", "TCGA-AB-2847",
"TCGA-AB-2849", "TCGA-AB-2851", "TCGA-AB-2853", "TCGA-AB-2856",
"TCGA-AB-2858", "TCGA-AB-2859", "TCGA-AB-2861", "TCGA-AB-2862",
"TCGA-AB-2863", "TCGA-AB-2865", "TCGA-AB-2866", "TCGA-AB-2867",
"TCGA-AB-2869", "TCGA-AB-2870", "TCGA-AB-2871", "TCGA-AB-2872",
"TCGA-AB-2873", "TCGA-AB-2874", "TCGA-AB-2875", "TCGA-AB-2876",
"TCGA-AB-2877", "TCGA-AB-2878", "TCGA-AB-2880", "TCGA-AB-2881",
"TCGA-AB-2882", "TCGA-AB-2883", "TCGA-AB-2884", "TCGA-AB-2885",
"TCGA-AB-2886", "TCGA-AB-2888", "TCGA-AB-2889", "TCGA-AB-2890",
"TCGA-AB-2891", "TCGA-AB-2892", "TCGA-AB-2893", "TCGA-AB-2894",
"TCGA-AB-2895", "TCGA-AB-2896", "TCGA-AB-2897", "TCGA-AB-2898",
"TCGA-AB-2899", "TCGA-AB-2900", "TCGA-AB-2901", "TCGA-AB-2908",
"TCGA-AB-2910", "TCGA-AB-2911", "TCGA-AB-2912", "TCGA-AB-2913",
"TCGA-AB-2914", "TCGA-AB-2915", "TCGA-AB-2916", "TCGA-AB-2917",
"TCGA-AB-2918", "TCGA-AB-2919", "TCGA-AB-2920", "TCGA-AB-2921",
"TCGA-AB-2924", "TCGA-AB-2925", "TCGA-AB-2927", "TCGA-AB-2928",
"TCGA-AB-2929", "TCGA-AB-2930", "TCGA-AB-2931", "TCGA-AB-2932",
"TCGA-AB-2933", "TCGA-AB-2934", "TCGA-AB-2935", "TCGA-AB-2936",
"TCGA-AB-2937", "TCGA-AB-2939", "TCGA-AB-2940", "TCGA-AB-2942",
"TCGA-AB-2943", "TCGA-AB-2944", "TCGA-AB-2946", "TCGA-AB-2948",
"TCGA-AB-2949", "TCGA-AB-2950", "TCGA-AB-2952", "TCGA-AB-2955",
"TCGA-AB-2956", "TCGA-AB-2959", "TCGA-AB-2963", "TCGA-AB-2965",
"TCGA-AB-2966", "TCGA-AB-2970", "TCGA-AB-2971", "TCGA-AB-2973",
"TCGA-AB-2975", "TCGA-AB-2976", "TCGA-AB-2977", "TCGA-AB-2979",
"TCGA-AB-2980", "TCGA-AB-2981", "TCGA-AB-2982", "TCGA-AB-2983",
"TCGA-AB-2984", "TCGA-AB-2986", "TCGA-AB-2987", "TCGA-AB-2988",
"TCGA-AB-2990", "TCGA-AB-2991", "TCGA-AB-2992", "TCGA-AB-2994",
"TCGA-AB-2995", "TCGA-AB-2996", "TCGA-AB-2998", "TCGA-AB-2999",
"TCGA-AB-3000", "TCGA-AB-3001", "TCGA-AB-3002", "TCGA-AB-3007",
"TCGA-AB-3008", "TCGA-AB-3009", "TCGA-AB-3011", "TCGA-AB-3012"
), class = "factor"), FAB = structure(c(5L, 1L, 5L, 3L, 2L, 4L
), .Label = c("M0", "M1", "M2", "M3", "M4", "M5"), class = "factor")), row.names = c(NA,
6L), class = "data.frame")
我想把這個資料框變成這個
> age
s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 s16 s17 s18 s19 s20 s21 s22 s23 s24 s25 s26 s27 s28 s29 s30 s31 s32 s33 s34 s35 s36 s37 s38
2 2 5 11 20 32 61 93 93 144 232 303 649 654 904 2 2 5 11 20 32 61 93 93 144 232 303 649 654 904 904 2 2 5 11 20 32 61
s39 s40 s41 s42 s43 s44 s45 s46 s47 s48 s49 s50 s51 s52 s53 s54 s55 s56 s57 s58 s59 s60 s61 s62 s63
93 93 144 232 303 649 654 904 904 2 2 5 11 20 32 61 93 93 144 232 303 649 654 904 904
> class(age)
[1] "numeric"
另一個是第二個資料框,它應該看起來像這樣
samp_tissue
s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 s16 s17
"Cortex" "Cortex" "Cortex" "Cortex" "Cortex" "Cortex" "Cortex" "Cortex" "Cortex" "Cortex" "Cortex" "Cortex" "Cortex" "Cortex" "Cortex" "Lung" "Lung"
s18 s19 s20 s21 s22 s23 s24 s25 s26 s27 s28 s29 s30 s31 s32 s33 s34
"Lung" "Lung" "Lung" "Lung" "Lung" "Lung" "Lung" "Lung" "Lung" "Lung" "Lung" "Lung" "Lung" "Lung" "Liver" "Liver" "Liver"
s35 s36 s37 s38 s39 s40 s41 s42 s43 s44 s45 s46 s47 s48 s49 s50 s51
"Liver" "Liver" "Liver" "Liver" "Liver" "Liver" "Liver" "Liver" "Liver" "Liver" "Liver" "Liver" "Liver" "Muscle" "Muscle" "Muscle" "Muscle"
s52 s53 s54 s55 s56 s57 s58 s59 s60 s61 s62 s63
"Muscle" "Muscle" "Muscle" "Muscle" "Muscle" "Muscle" "Muscle" "Muscle" "Muscle" "Muscle" "Muscle" "Muscle"
我想知道如何將它們轉換為上述型別。
我試圖搜索,但我不確定找到我要查找的內容的正確查詢
我從這篇文章中得到的可能的解決方案
whatyouwant <- setNames( as.numeric(Age$Blast_Percentage),as.character(Age$patient))
class(whatyouwant)
what <- setNames( as.character(Sample_info$FAB),as.character(Age$patient))
class(what)
what
uj5u.com熱心網友回復:
我不清楚您的預期結果(即使用您的樣本資料,最終結果應該是什么?),但也許您正在尋找table()(我對“a”的猜測)或deframe()來自 tibble 包:
library(tibble)
a <- structure(list(Blast_Percentage = c(82L, 83L, 91L, 72L, 68L,
88L)), row.names = c("TCGA-AB-2856", "TCGA-AB-2849", "TCGA-AB-2971",
"TCGA-AB-2930", "TCGA-AB-2891", "TCGA-AB-2872"), class = "data.frame")
b <- structure(list(patient = structure(c(35L, 32L, 118L, 93L, 64L,
47L), .Label = c("TCGA-AB-2805", "TCGA-AB-2806", "TCGA-AB-2808",
"TCGA-AB-2810", "TCGA-AB-2811", "TCGA-AB-2812", "TCGA-AB-2813",
"TCGA-AB-2814", "TCGA-AB-2815", "TCGA-AB-2817", "TCGA-AB-2818",
"TCGA-AB-2819", "TCGA-AB-2820", "TCGA-AB-2821", "TCGA-AB-2822",
"TCGA-AB-2823", "TCGA-AB-2825", "TCGA-AB-2826", "TCGA-AB-2828",
"TCGA-AB-2830", "TCGA-AB-2834", "TCGA-AB-2835", "TCGA-AB-2836",
"TCGA-AB-2839", "TCGA-AB-2840", "TCGA-AB-2841", "TCGA-AB-2842",
"TCGA-AB-2844", "TCGA-AB-2845", "TCGA-AB-2846", "TCGA-AB-2847",
"TCGA-AB-2849", "TCGA-AB-2851", "TCGA-AB-2853", "TCGA-AB-2856",
"TCGA-AB-2858", "TCGA-AB-2859", "TCGA-AB-2861", "TCGA-AB-2862",
"TCGA-AB-2863", "TCGA-AB-2865", "TCGA-AB-2866", "TCGA-AB-2867",
"TCGA-AB-2869", "TCGA-AB-2870", "TCGA-AB-2871", "TCGA-AB-2872",
"TCGA-AB-2873", "TCGA-AB-2874", "TCGA-AB-2875", "TCGA-AB-2876",
"TCGA-AB-2877", "TCGA-AB-2878", "TCGA-AB-2880", "TCGA-AB-2881",
"TCGA-AB-2882", "TCGA-AB-2883", "TCGA-AB-2884", "TCGA-AB-2885",
"TCGA-AB-2886", "TCGA-AB-2888", "TCGA-AB-2889", "TCGA-AB-2890",
"TCGA-AB-2891", "TCGA-AB-2892", "TCGA-AB-2893", "TCGA-AB-2894",
"TCGA-AB-2895", "TCGA-AB-2896", "TCGA-AB-2897", "TCGA-AB-2898",
"TCGA-AB-2899", "TCGA-AB-2900", "TCGA-AB-2901", "TCGA-AB-2908",
"TCGA-AB-2910", "TCGA-AB-2911", "TCGA-AB-2912", "TCGA-AB-2913",
"TCGA-AB-2914", "TCGA-AB-2915", "TCGA-AB-2916", "TCGA-AB-2917",
"TCGA-AB-2918", "TCGA-AB-2919", "TCGA-AB-2920", "TCGA-AB-2921",
"TCGA-AB-2924", "TCGA-AB-2925", "TCGA-AB-2927", "TCGA-AB-2928",
"TCGA-AB-2929", "TCGA-AB-2930", "TCGA-AB-2931", "TCGA-AB-2932",
"TCGA-AB-2933", "TCGA-AB-2934", "TCGA-AB-2935", "TCGA-AB-2936",
"TCGA-AB-2937", "TCGA-AB-2939", "TCGA-AB-2940", "TCGA-AB-2942",
"TCGA-AB-2943", "TCGA-AB-2944", "TCGA-AB-2946", "TCGA-AB-2948",
"TCGA-AB-2949", "TCGA-AB-2950", "TCGA-AB-2952", "TCGA-AB-2955",
"TCGA-AB-2956", "TCGA-AB-2959", "TCGA-AB-2963", "TCGA-AB-2965",
"TCGA-AB-2966", "TCGA-AB-2970", "TCGA-AB-2971", "TCGA-AB-2973",
"TCGA-AB-2975", "TCGA-AB-2976", "TCGA-AB-2977", "TCGA-AB-2979",
"TCGA-AB-2980", "TCGA-AB-2981", "TCGA-AB-2982", "TCGA-AB-2983",
"TCGA-AB-2984", "TCGA-AB-2986", "TCGA-AB-2987", "TCGA-AB-2988",
"TCGA-AB-2990", "TCGA-AB-2991", "TCGA-AB-2992", "TCGA-AB-2994",
"TCGA-AB-2995", "TCGA-AB-2996", "TCGA-AB-2998", "TCGA-AB-2999",
"TCGA-AB-3000", "TCGA-AB-3001", "TCGA-AB-3002", "TCGA-AB-3007",
"TCGA-AB-3008", "TCGA-AB-3009", "TCGA-AB-3011", "TCGA-AB-3012"
), class = "factor"), FAB = structure(c(5L, 1L, 5L, 3L, 2L, 4L
), .Label = c("M0", "M1", "M2", "M3", "M4", "M5"), class = "factor")), row.names = c(NA,
6L), class = "data.frame")
table(a)
#> a
#> 68 72 82 83 88 91
#> 1 1 1 1 1 1
deframe(b)
#> TCGA-AB-2856 TCGA-AB-2849 TCGA-AB-2971 TCGA-AB-2930 TCGA-AB-2891 TCGA-AB-2872
#> M4 M0 M4 M2 M1 M3
#> Levels: M0 M1 M2 M3 M4 M5
由reprex 包于 2022-06-29 創建(v2.0.1)
或者也許這個?
library(tidyverse)
a %>%
rownames_to_column("patient") %>%
left_join(b)
#> Joining, by = "patient"
#> patient Blast_Percentage FAB
#> 1 TCGA-AB-2856 82 M4
#> 2 TCGA-AB-2849 83 M0
#> 3 TCGA-AB-2971 91 M4
#> 4 TCGA-AB-2930 72 M2
#> 5 TCGA-AB-2891 68 M1
#> 6 TCGA-AB-2872 88 M3
由reprex 包于 2022-06-29 創建(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/497351.html
標籤:r
上一篇:新列取決于其余R的值
下一篇:如何使用可用的最后日期創建變數
