将数据帧转换为R中的布尔值
我有一个信号通路的样本列表,如果发生了突变,样本数量如下:1,如果没有发生突变,样本数量为0将数据帧转换为R中的布尔值,r,dplyr,formatting,data.table,reshape,R,Dplyr,Formatting,Data.table,Reshape,我有一个信号通路的样本列表,如果发生了突变,样本数量如下:1,如果没有发生突变,样本数量为0 > dput(pathway) structure(list(sample = c("LP6005334.DNA_H01", "LP6005334.DNA_H01", "LP6005334.DNA_H01", "LP6005334.DNA_H01", "LP6005334.DNA_H01",
> dput(pathway)
structure(list(sample = c("LP6005334.DNA_H01", "LP6005334.DNA_H01",
"LP6005334.DNA_H01", "LP6005334.DNA_H01", "LP6005334.DNA_H01",
"LP6005334.DNA_H01", "LP6005334.DNA_H01", "LP6005334.DNA_H01",
"LP6005334.DNA_H01", "LP6005334.DNA_H01", "LP6005334.DNA_H01",
"LP6005334.DNA_H01", "LP6005500.DNA_D03", "LP6005500.DNA_D03",
"LP6005500.DNA_D03", "LP6005500.DNA_D03", "LP6005500.DNA_D03",
"LP6005500.DNA_D03", "LP6005500.DNA_D03", "LP6005500.DNA_D03",
"LP6005500.DNA_D03", "LP6005500.DNA_D03", "LP6005500.DNA_D03",
"LP6005500.DNA_D03", "LP6005500.DNA_D03", "LP6007600", "LP6007600",
"LP6007600", "LP6007600", "LP6007600", "LP6007600", "LP6007600",
"LP6007600", "LP6007600", "LP6007600", "LP6007600", "LP6007600",
"LP6008202.DNA_B03", "LP6008202.DNA_B03", "LP6008202.DNA_B03",
"LP6008202.DNA_B03", "LP6008202.DNA_B03", "LP6008202.DNA_B03",
"LP6008202.DNA_B03", "LP6008202.DNA_B03", "LP6008202.DNA_B03",
"LP6008202.DNA_B03", "LP6008202.DNA_B03", "LP6008202.DNA_B03",
"LP6008334.DNA_A03", "LP6008334.DNA_A03", "LP6008334.DNA_A03",
"LP6008334.DNA_A03", "LP6008334.DNA_A03", "LP6008334.DNA_A03",
"LP6008334.DNA_A03", "LP6008334.DNA_A03", "LP6008334.DNA_A03",
"LP6008334.DNA_A03", "LP6008334.DNA_A03", "LP6008334.DNA_A03",
"LP6008334.DNA_A04", "LP6008334.DNA_A04", "LP6008334.DNA_A04",
"LP6008334.DNA_A04", "LP6008334.DNA_A04", "LP6008334.DNA_A04",
"LP6008334.DNA_A04", "LP6008334.DNA_A04", "LP6008334.DNA_A04",
"LP6008334.DNA_A04", "LP6008334.DNA_A04", "LP6008334.DNA_A04",
"LP6008334.DNA_B02", "LP6008334.DNA_B02", "LP6008334.DNA_B02",
"LP6008334.DNA_B02", "LP6008334.DNA_B02", "LP6008334.DNA_B02",
"LP6008334.DNA_B02", "LP6008334.DNA_B02", "LP6008334.DNA_B02",
"LP6008334.DNA_B02", "LP6008334.DNA_B02", "LP6008334.DNA_B02",
"LP6008334.DNA_C02", "LP6008334.DNA_C02", "LP6008334.DNA_C02",
"LP6008334.DNA_C02", "LP6008334.DNA_C02", "LP6008334.DNA_C02",
"LP6008334.DNA_C02", "LP6008334.DNA_C02", "LP6008334.DNA_C02",
"LP6008334.DNA_C02", "LP6008334.DNA_C02", "LP6008334.DNA_C02",
"LP6008334.DNA_D02", "LP6008334.DNA_D02", "LP6008334.DNA_D02",
"LP6008334.DNA_D02", "LP6008334.DNA_D02", "LP6008334.DNA_D02",
"LP6008334.DNA_D02", "LP6008334.DNA_D02", "LP6008334.DNA_D02",
"LP6008334.DNA_D02", "LP6008334.DNA_D02", "LP6008334.DNA_D02",
"LP6008336.DNA_F02", "LP6008336.DNA_F02", "LP6008336.DNA_F02",
"LP6008336.DNA_F02", "LP6008336.DNA_F02", "LP6008336.DNA_F02",
"LP6008336.DNA_F02", "LP6008336.DNA_F02", "LP6008336.DNA_F02",
"LP6008336.DNA_F02", "LP6008336.DNA_F02", "LP6008336.DNA_F02",
"LP6008336.DNA_G01", "LP6008336.DNA_G01", "LP6008336.DNA_G01",
"LP6008336.DNA_G01", "LP6008336.DNA_G01", "LP6008336.DNA_G01",
"LP6008336.DNA_G01", "LP6008336.DNA_G01", "LP6008336.DNA_G01",
"LP6008336.DNA_G01", "LP6008336.DNA_G01", "LP6008336.DNA_G01",
"LP6008336.DNA_H01", "LP6008336.DNA_H01", "LP6008336.DNA_H01",
"LP6008336.DNA_H01", "LP6008336.DNA_H01", "LP6008336.DNA_H01",
"LP6008336.DNA_H01", "LP6008336.DNA_H01", "LP6008336.DNA_H01",
"LP6008336.DNA_H01", "LP6008336.DNA_H01", "LP6008336.DNA_H01",
"LP6008337.DNA_A07", "LP6008337.DNA_A07", "LP6008337.DNA_A07",
"LP6008337.DNA_A07", "LP6008337.DNA_A07", "LP6008337.DNA_A07",
"LP6008337.DNA_A07", "LP6008337.DNA_A07", "LP6008337.DNA_A07",
"LP6008337.DNA_A07", "LP6008337.DNA_A07", "LP6008337.DNA_A07",
"LP6008337.DNA_H06", "LP6008337.DNA_H06", "LP6008337.DNA_H06",
"LP6008337.DNA_H06", "LP6008337.DNA_H06", "LP6008337.DNA_H06",
"LP6008337.DNA_H06", "LP6008337.DNA_H06", "LP6008337.DNA_H06",
"LP6008337.DNA_H06", "LP6008337.DNA_H06", "LP6008337.DNA_H06",
"LP6008460.DNA_A04", "LP6008460.DNA_A04", "LP6008460.DNA_A04",
"LP6008460.DNA_A04", "LP6008460.DNA_A04", "LP6008460.DNA_A04",
"LP6008460.DNA_A04", "LP6008460.DNA_A04", "LP6008460.DNA_A04",
"LP6008460.DNA_A04", "LP6008460.DNA_A04", "LP6008460.DNA_A04",
"LP6008460.DNA_D01", "LP6008460.DNA_D01", "LP6008460.DNA_D01",
"LP6008460.DNA_D01", "LP6008460.DNA_D01", "LP6008460.DNA_D01",
"LP6008460.DNA_D01", "LP6008460.DNA_D01", "LP6008460.DNA_D01",
"LP6008460.DNA_D01", "LP6008460.DNA_D01", "LP6008460.DNA_D01",
"LP6008460.DNA_F02", "LP6008460.DNA_F02", "LP6008460.DNA_F02",
"LP6008460.DNA_F02", "LP6008460.DNA_F02", "LP6008460.DNA_F02",
"LP6008460.DNA_F02", "LP6008460.DNA_F02", "LP6008460.DNA_F02",
"LP6008460.DNA_F02", "LP6008460.DNA_F02", "LP6008460.DNA_F02",
"LP6008460.DNA_G03", "LP6008460.DNA_G03", "LP6008460.DNA_G03",
"LP6008460.DNA_G03", "LP6008460.DNA_G03", "LP6008460.DNA_G03",
"LP6008460.DNA_G03", "LP6008460.DNA_G03", "LP6008460.DNA_G03",
"LP6008460.DNA_G03", "LP6008460.DNA_G03", "LP6008460.DNA_G03",
"s15", "s15", "s15", "s15", "s15", "s15", "s15", "s15", "s15",
"s15", "s15", "s15", "s15", "s15", "s18", "s18", "s18", "s18",
"s18", "s18", "s18", "s18", "s18", "s18", "s18", "s18", "s18",
"s18", "s18", "s18", "s24", "s24", "s24", "s24", "s24", "s24",
"s24", "s24", "s24", "s24", "s24", "s24", "s24", "s24", "s24",
"s30", "s30", "s30", "s30", "s30", "s30", "s30", "s30", "s30",
"s30", "s30", "s30", "s30", "s30", "s59", "s59", "s59", "s59",
"s59", "s59", "s59", "s59", "s59", "s59", "s59", "s59", "s67",
"s67", "s67", "s67", "s67", "s67", "s67", "s67", "s67", "s67",
"s67", "s67", "s67", "s67", "s80", "s80", "s80", "s80", "s80",
"s80", "s80", "s80", "s80", "s80", "s80", "s80", "s80", "s80",
"s80", "s80", "s86", "s86", "s86", "s86", "s86", "s86", "s86",
"s86", "s86", "s86", "s86", "s86", "s86", "s86", "s94", "s94",
"s94", "s94", "s94", "s94", "s94", "s94", "s94", "s94", "s94",
"s94", "s94", "s94"), Pathway = c("PI3K", "Cell_Cycle", "RTK-RAS",
"WNT", "TGF-Beta", "CR", "CF", "TP53", "NOTCH", "Hippo", "MYC",
"NRF2", "PI3K", "Cell_Cycle", "WNT", "TGF-Beta", "RTK-RAS", "WNT",
"CR", "CF", "TP53", "NOTCH", "Hippo", "MYC", "NRF2", "TGF-Beta",
"PI3K", "RTK-RAS", "WNT", "CR", "CF", "TP53", "Cell_Cycle", "NOTCH",
"Hippo", "MYC", "NRF2", "PI3K", "TGF-Beta", "RTK-RAS", "WNT",
"CR", "CF", "TP53", "Cell_Cycle", "NOTCH", "Hippo", "MYC", "NRF2",
"Cell_Cycle", "TGF-Beta", "PI3K", "RTK-RAS", "WNT", "CR", "CF",
"TP53", "NOTCH", "Hippo", "MYC", "NRF2", "RTK-RAS", "TGF-Beta",
"PI3K", "WNT", "CR", "CF", "TP53", "Cell_Cycle", "NOTCH", "Hippo",
"MYC", "NRF2", "Cell_Cycle", "TGF-Beta", "PI3K", "RTK-RAS", "WNT",
"CR", "CF", "TP53", "NOTCH", "Hippo", "MYC", "NRF2", "PI3K",
"Cell_Cycle", "RTK-RAS", "TGF-Beta", "WNT", "CR", "CF", "TP53",
"NOTCH", "Hippo", "MYC", "NRF2", "PI3K", "Cell_Cycle", "TGF-Beta",
"RTK-RAS", "WNT", "CR", "CF", "TP53", "NOTCH", "Hippo", "MYC",
"NRF2", "Cell_Cycle", "TGF-Beta", "PI3K", "RTK-RAS", "WNT", "CR",
"CF", "TP53", "NOTCH", "Hippo", "MYC", "NRF2", "TGF-Beta", "PI3K",
"RTK-RAS", "WNT", "CR", "CF", "TP53", "Cell_Cycle", "NOTCH",
"Hippo", "MYC", "NRF2", "PI3K", "Cell_Cycle", "WNT", "TGF-Beta",
"RTK-RAS", "CR", "CF", "TP53", "NOTCH", "Hippo", "MYC", "NRF2",
"PI3K", "TGF-Beta", "RTK-RAS", "WNT", "CR", "CF", "TP53", "Cell_Cycle",
"NOTCH", "Hippo", "MYC", "NRF2", "Cell_Cycle", "RTK-RAS", "TGF-Beta",
"PI3K", "WNT", "CR", "CF", "TP53", "NOTCH", "Hippo", "MYC", "NRF2",
"Cell_Cycle", "TGF-Beta", "PI3K", "RTK-RAS", "WNT", "CR", "CF",
"TP53", "NOTCH", "Hippo", "MYC", "NRF2", "Cell_Cycle", "CF",
"CR", "Hippo", "MYC", "NOTCH", "NRF2", "PI3K", "RTK-RAS", "TGF-Beta",
"TP53", "WNT", "Cell_Cycle", "RTK-RAS", "TGF-Beta", "PI3K", "WNT",
"CR", "CF", "TP53", "NOTCH", "Hippo", "MYC", "NRF2", "RTK-RAS",
"TGF-Beta", "PI3K", "WNT", "CR", "CF", "TP53", "Cell_Cycle",
"NOTCH", "Hippo", "MYC", "NRF2", "Cell_Cycle", "RTK-RAS", "TGF-Beta",
"PI3K", "RTK-RAS", "WNT", "CR", "CF", "TP53", "Cell_Cycle", "NOTCH",
"Hippo", "MYC", "NRF2", "PI3K", "Cell_Cycle", "RTK-RAS", "WNT",
"TGF-Beta", "RTK-RAS", "WNT", "CR", "CF", "TP53", "Cell_Cycle",
"NOTCH", "Hippo", "MYC", "NRF2", "PI3K", "PI3K", "Cell_Cycle",
"RTK-RAS", "TGF-Beta", "RTK-RAS", "WNT", "CR", "CF", "TP53",
"Cell_Cycle", "NOTCH", "Hippo", "MYC", "NRF2", "PI3K", "Cell_Cycle",
"WNT", "TGF-Beta", "PI3K", "RTK-RAS", "WNT", "CR", "CF", "TP53",
"Cell_Cycle", "NOTCH", "Hippo", "MYC", "NRF2", "TGF-Beta", "PI3K",
"RTK-RAS", "WNT", "CR", "CF", "TP53", "Cell_Cycle", "NOTCH",
"Hippo", "MYC", "NRF2", "Cell_Cycle", "WNT", "TGF-Beta", "PI3K",
"RTK-RAS", "WNT", "CR", "CF", "TP53", "Cell_Cycle", "NOTCH",
"Hippo", "MYC", "NRF2", "PI3K", "Cell_Cycle", "RTK-RAS", "WNT",
"TGF-Beta", "RTK-RAS", "WNT", "CR", "CF", "TP53", "Cell_Cycle",
"NOTCH", "Hippo", "MYC", "NRF2", "PI3K", "Cell_Cycle", "WNT",
"TGF-Beta", "PI3K", "RTK-RAS", "WNT", "CR", "CF", "TP53", "Cell_Cycle",
"NOTCH", "Hippo", "MYC", "NRF2", "Cell_Cycle", "RTK-RAS", "TGF-Beta",
"PI3K", "RTK-RAS", "WNT", "CR", "CF", "TP53", "Cell_Cycle", "NOTCH",
"Hippo", "MYC", "NRF2"), value = c(1L, 1L, 1L, 1L, 0L, 0L, 0L,
0L, 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0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L)), class = "data.frame", row.names = c(NA, -346L))
我想将其转换为布尔矩阵(宽格式),其中路径在列中,样本在行中
如果一条途径发生了突变,一个样本获得1,如果一条类似的途径未发生突变,则获得0
> head(p)
sample value Cell_Cycle Hippo MYC NOTCH NRF2 PI3K TGF-Beta RTK-RAS TP53
1 LP6008334.DNA_C02 0 0 0 0 0 0 0 0 0 0
2 LP6008334.DNA_A03 0 0 0 0 0 0 0 0 0 0
3 LP6005334.DNA_H01 0 0 0 0 0 0 0 0 0 0
4 LP6008337.DNA_H06 0 0 0 0 0 0 0 0 0 0
5 s15 0 0 0 0 0 0 0 0 0 0
6 LP6008460.DNA_D01 0 0 0 0 0 0 0 0 0 0
WNT CF CR
1 0 0 0
2 0 0 0
3 0 0 0
4 0 0 0
5 0 0 0
6 0 0 0
>
但我得到的都是零
我试过这个
for (pathway in setdiff(unique(p$Pathway), colnames(p))) {
p <- cbind(p,array(0,nrow(p)))
colnames(p)[ncol(p)] <- pathway
}
但是给出了错误的0和1
请帮助我我们可以使用
表格
+(table(p[, c("sample", "Pathway")]) > 0)
请为你的数据做一个可复制的例子。谢谢,我做了一个可复制的例子
+(table(p[, c("sample", "Pathway")]) > 0)