Dear all, I have a vector of length 1 but within this vector there are 9 elements> vectorNOcorrection[1] "(O, O, O, H, L, O, O, O, O)" can someone help me with how I can have it as with 9 element separated such that it will have length 9 as "O", "O"," O", "H","L", "O", "O", "O", "O" Kind regards, Jessy [[alternative HTML version deleted]]
You can use gsub() to eliminate the parentheses, and strsplit() to separate the elements. Sarah On Thursday, June 28, 2012, Jessy wrote:> Dear all, > > I have a vector of length 1 but within this vector there are 9 elements > > vectorNOcorrection > [1] "(O, O, O, H, L, O, O, O, O)" > can someone help me with how I can have it as with 9 element separated > such that it will have length 9 as "O", "O"," O", "H","L", "O", "O", "O", > "O" > > Kind regards, > Jessy > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org <javascript:;> mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[alternative HTML version deleted]]
Hello,
Try
x <- "(O, O, O, H, L, O, O, O, O)"
strsplit(gsub("\\(|\\)|[[:blank:]]", "", x), ",")
Note that the result is a list, not a vector. You can then use `[[` or
unlist().
Hope this helps,
Rui Barradas
Em 28-06-2012 11:42, Jessy escreveu:> Dear all,
>
> I have a vector of length 1 but within this vector there are 9 elements
>> vectorNOcorrection
> [1] "(O, O, O, H, L, O, O, O, O)"
> can someone help me with how I can have it as with 9 element separated
> such that it will have length 9 as "O", "O","
O", "H","L", "O", "O",
"O",
> "O"
>
> Kind regards,
> Jessy
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>