separate 2 delimiter
1
0
Entering edit mode
10.5 years ago
minni9234 ▴ 50

Hi,

How to separate 2 delimiters (- and ///) for a dataset? I only know how to separate one delimiter.

genenames=as.character(rownames(selExpr)) 
delim.ind=grep("///",genenames) 

tmpgene=NA # object for single gene names

for (i in 1:length(delim.ind)){  
  tmp=strsplit(as.character(genenames[delim.ind[i]]),"///",fixed=TRUE) 
  tmpgene[i]=tmp[[1]][1]  # just want the first name
}  # need to iterate b/c some rows have more than one ///

genenames[delim.ind]=tmpgene
rownames(selExpr)=genenames
R • 1.7k views
ADD COMMENT
0
Entering edit mode
Having two different delimiters in the same file is not a good idea, and a potential source of errors in the future. That is probably the reason why read.table in r doesn't have am option to read more than one delimiter. You should edit the file with sed, and unify all the delimiters in a single one.
ADD REPLY
0
Entering edit mode
10.5 years ago
strs <- c("A /// B - C /// D - E", "F /// G - H /// I - J")
lapply(as.list(strs), function(x) unlist(strsplit(unlist(strsplit(x, " /// ", fixed=T)), " - ", fixed=T)))

The output will be a list:

[[1]]
[1] "A" "B" "C" "D" "E"

[[2]]
[1] "F" "G" "H" "I" "J"
ADD COMMENT

Login before adding your answer.

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