0

the split as shown below is driving me crazy...nee somehelp to spot where is the problem

> p5<-Data$poorcoverageusers[5]
> p5
[1] "405874050693761|405874004853834|405874056470063|405874055308702"
> strsplit(p5,"|")
[[1]]
 [1] "4" "0" "5" "8" "7" "4" "0" "5" "0" "6" "9" "3" "7" "6" "1" "|" "4" "0" "5" "8" "7" "4" "0" "0" "4" "8" "5" "3" "8" "3" "4" "|" "4" "0" "5"
[36] "8" "7" "4" "0" "5" "6" "4" "7" "0" "0" "6" "3" "|" "4" "0" "5" "8" "7" "4" "0" "5" "5" "3" "0" "8" "7" "0" "2"

> typeof(Data$poorcoverageusers[5])
[1] "character"

i wanted it to be splitted by "|"... so output should have been 405874050693761 405874004853834 405874056470063 405874055308702

what is he mistake i m making..

thnks for help

r

onyambu
  • 49,350
  • 3
  • 19
  • 45
rajibc
  • 83
  • 9

1 Answers1

0
library(stringr)

s <- "405874050693761|405874004853834|405874056470063|405874055308702"

str_split(s, fixed("|"))                # returns a list of character vectors
# [[1]]
# [1] "405874050693761" "405874004853834" "405874056470063" "405874055308702"

str_split(s, fixed("|"), simplify = T)  # returns a character matrix
#      [,1]              [,2]              [,3]              [,4]             
# [1,] "405874050693761" "405874004853834" "405874056470063" "405874055308702"
Ozan
  • 2,606
  • 1
  • 11
  • 24