make a vector containing several vectors in to a single one
1
0
Entering edit mode
3.8 years ago
Kai_Qi ▴ 130

I extract a column from CSV containing geneName from geneOntology analysis. The result is a vector that contains several sub-vectors.

Now I want to make all elements into a single vector instead of a vector containing several vectors, what is the convenient way to do this?

Thank you,

R • 667 views
ADD COMMENT
0
Entering edit mode

Data examples please, words alone are typically not sufficient.

ADD REPLY
0
Entering edit mode
geneOntology <- read.csv("IRE11_combind_E18_David_Direct_BP.csv", stringsAsFactors = FALSE)
genes <- geneOntology$Genes[geneOntology$Group == "E18>E11"]
genes
[1] "ERCC6L2, CDC14B, XRCC6, PRKDC, INO80, BCCIP, SPRTN, DMAP1, KIN, MUTYH, ERCC6, MDC1, ACTR5, POLM, HINFP, USP10, ACTR8, FANCG, RTEL1, SLX1B, EME2, NFRKB, LIG1, NEIL1, LIG3, PNKP, USP28, RPAIN, TDP2, ABL1, PARP2"                                                                                                                                                                                                                                                                                                                                                                                                                                                
 [2] "GTPBP4, WBSCR22, ERAL1, IPO9, BMS1, NVL, DROSHA, IPO4, TSR3, ZNHIT6, UTP14A, SETD4, FTSJ3, GNL3, DDX51"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
 [3] "RECQL4, SLX1B, EME2, LIG1, NFRKB, XRCC6, LIG3, INO80, KIN, RPAIN, ACTR5, POLM, ACTR8, RTEL1"

In this case the genes contains 3 sub-vectors. How to fuse the 3 sub-vectors directly into 1?

ADD REPLY
0
Entering edit mode

Probably unlist()

ADD REPLY
0
Entering edit mode

I tried it. It works on list. I even tried to use as.list to transform the genes into a list and then do unlist. Still does not work

ADD REPLY
0
Entering edit mode

How about

unlist(lapply(genes, function(x)x))
ADD REPLY
0
Entering edit mode
y <- unlist(lapply(genes, function(x)x))
> y[1]
[1] "ERCC6L2, CDC14B, XRCC6, PRKDC, INO80, BCCIP, SPRTN, DMAP1, KIN, MUTYH, ERCC6, MDC1, ACTR5, POLM, HINFP, USP10, ACTR8, FANCG, RTEL1, SLX1B, EME2, NFRKB, LIG1, NEIL1, LIG3, PNKP, USP28, RPAIN, TDP2, ABL1, PARP2"

Looks still not working.

ADD REPLY
1
Entering edit mode
3.8 years ago
ATpoint 82k

it is difficult to help since you provide no copy/paste ready data, try

gsub(" ", "", unlist(sapply(strsplit(genes, split = ","), function(x)x)))

and if this does not work then please use dput to provide the data so we can reproduce things.

ADD COMMENT
1
Entering edit mode

It worked! I will learn to use dput to provide data in the future post!

Appreciate a lot!

ADD REPLY

Login before adding your answer.

Traffic: 1945 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