I have a string a="100111" and want to split it and store as b=("1","0","0","1","1","1") as a list with length =6. I tried splitting using srtsplit but I end up with a list b = ("1" "0" "0" "1" "1" "1"), with length = 1. The end goal is to get which positions in the string "100111" has 1. For example when I split a and store it in b as ("1","0","0","1","1","1") and then use which(b=='1') it want to get (1,4,5,6)
which(unlist(strsplit(a, split="")) == 1)will do it. you have to pull the vector out of the list withunlist.