[R] strsplit and forward slash '/'

2011-08-03 Thread Federico Calboli
Hi All,

is there a way of using strsplit with a forward slash '/' as the splitting 
point?

For data such as:

1  T/TC/C  16/33
2  T/TC/C  33/36
3  T/TC/C  16/34
4  T/TC/C  16/31
5  C/CC/C  28/29
6  T/TC/C  16/34

strsplit(my.data[1,1], /) # and any variation thereof 
Error in strsplit(apoe[1, 1], /) : non-character argument

Any advice will be gratefully received.

Best wishes,

Federico


--
Federico C. F. Calboli
Department of Epidemiology and Biostatistics
Imperial College, St. Mary's Campus
Norfolk Place, London W2 1PG

Tel +44 (0)20 75941602   Fax +44 (0)20 75943193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com

__
R-help@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.


Re: [R] strsplit and forward slash '/'

2011-08-03 Thread Duncan Murdoch

On 03/08/2011 12:37 PM, Federico Calboli wrote:

Hi All,

is there a way of using strsplit with a forward slash '/' as the splitting 
point?

For data such as:

1  T/TC/C  16/33
2  T/TC/C  33/36
3  T/TC/C  16/34
4  T/TC/C  16/31
5  C/CC/C  28/29
6  T/TC/C  16/34

strsplit(my.data[1,1], /) # and any variation thereof
Error in strsplit(apoe[1, 1], /) : non-character argument


It looks as though your my.data[1,1] value is a factor, not a character 
value.


strsplit(as.character(my.data[1,1]), /)

would work, or you could avoid getting factors in the first place, using the 
stringsAsFactors argument when you create the dataframe.

Duncan Murdoch



Any advice will be gratefully received.

Best wishes,

Federico


--
Federico C. F. Calboli
Department of Epidemiology and Biostatistics
Imperial College, St. Mary's Campus
Norfolk Place, London W2 1PG

Tel +44 (0)20 75941602   Fax +44 (0)20 75943193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com

__
R-help@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.


__
R-help@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.


Re: [R] strsplit and forward slash '/'

2011-08-03 Thread Sarah Goslee
Hi Federico,

A forward slash isn't a special character:

 strsplit(T/T, /)
[[1]]
[1] T T

so there's some other problem.

Are you sure that your first column contains strings and not factors?
What does str(my.data) tell you?

Does
strsplit(as.character(my.data[1,1]), /)
work?

If you used read.table() to get your data in, you might want the
as.is=TRUE or the stringsAsFactors=FALSE argument.

Sarah

On Wed, Aug 3, 2011 at 12:37 PM, Federico Calboli
f.calb...@imperial.ac.uk wrote:
 Hi All,

 is there a way of using strsplit with a forward slash '/' as the splitting 
 point?

 For data such as:

 1      T/T    C/C  16/33
 2      T/T    C/C  33/36
 3      T/T    C/C  16/34
 4      T/T    C/C  16/31
 5      C/C    C/C  28/29
 6      T/T    C/C  16/34

 strsplit(my.data[1,1], /) # and any variation thereof
 Error in strsplit(apoe[1, 1], /) : non-character argument

 Any advice will be gratefully received.

 Best wishes,

 Federico




-- 
Sarah Goslee
http://www.sarahgoslee.com

__
R-help@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.


Re: [R] strsplit and forward slash '/'

2011-08-03 Thread Federico Calboli
On 3 Aug 2011, at 17:41, Duncan Murdoch wrote:

 
 It looks as though your my.data[1,1] value is a factor, not a character value.
 
 strsplit(as.character(my.data[1,1]), /)

Thanks Duncan, this solved it.

Best 

Federico


 
 would work, or you could avoid getting factors in the first place, using the 
 stringsAsFactors argument when you create the dataframe.
 
 Duncan Murdoch
 
 
 Any advice will be gratefully received.
 
 Best wishes,
 
 Federico
 
 
 --
 Federico C. F. Calboli
 Department of Epidemiology and Biostatistics
 Imperial College, St. Mary's Campus
 Norfolk Place, London W2 1PG
 
 Tel +44 (0)20 75941602   Fax +44 (0)20 75943193
 
 f.calboli [.a.t] imperial.ac.uk
 f.calboli [.a.t] gmail.com
 
 __
 R-help@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.
 

--
Federico C. F. Calboli
Department of Epidemiology and Biostatistics
Imperial College, St. Mary's Campus
Norfolk Place, London W2 1PG

Tel +44 (0)20 75941602   Fax +44 (0)20 75943193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com

__
R-help@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.


Re: [R] strsplit and forward slash '/'

2011-08-03 Thread Federico Calboli

On 3 Aug 2011, at 17:46, Sarah Goslee wrote:

 Hi Federico,
 
 A forward slash isn't a special character:
 
 strsplit(T/T, /)
 [[1]]
 [1] T T
 
 so there's some other problem.
 
 Are you sure that your first column contains strings and not factors?
 What does str(my.data) tell you?
 
 Does
 strsplit(as.character(my.data[1,1]), /)
 work?

yes!

Thanks

Federico


 
 If you used read.table() to get your data in, you might want the
 as.is=TRUE or the stringsAsFactors=FALSE argument.
 
 Sarah
 
 On Wed, Aug 3, 2011 at 12:37 PM, Federico Calboli
 f.calb...@imperial.ac.uk wrote:
 Hi All,
 
 is there a way of using strsplit with a forward slash '/' as the splitting 
 point?
 
 For data such as:
 
 1  T/TC/C  16/33
 2  T/TC/C  33/36
 3  T/TC/C  16/34
 4  T/TC/C  16/31
 5  C/CC/C  28/29
 6  T/TC/C  16/34
 
 strsplit(my.data[1,1], /) # and any variation thereof
 Error in strsplit(apoe[1, 1], /) : non-character argument
 
 Any advice will be gratefully received.
 
 Best wishes,
 
 Federico
 
 
 
 
 -- 
 Sarah Goslee
 http://www.sarahgoslee.com

--
Federico C. F. Calboli
Department of Epidemiology and Biostatistics
Imperial College, St. Mary's Campus
Norfolk Place, London W2 1PG

Tel +44 (0)20 75941602   Fax +44 (0)20 75943193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com

__
R-help@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.