From bibiko at eva.mpg.de  Tue Oct 25 01:04:46 2011
From: bibiko at eva.mpg.de (=?iso-8859-1?Q?Hans-J=F6rg_Bibiko?=)
Date: Tue, 25 Oct 2011 01:04:46 +0200
Subject: [Rd] strsplit convert data
In-Reply-To: <1319495640961-3934808.post@n4.nabble.com>
References: <1319452277838-3932704.post@n4.nabble.com>
	<1319477336.8217.1.camel@milan>
	<1319495640961-3934808.post@n4.nabble.com>
Message-ID: <D79B01D9-051E-4833-B155-39B97CAF4AC0@eva.mpg.de>

On 25 Oct 2011, at 00:34, RMSOPS wrote:
>   To be more specific, my problem is here
> Line <-dataset $ Items [i]
>   print (line)
>   in.s <- strsplit (line, '')
> 
> I am reading lines from a file
> Line 1 A, B, C, D, G
> Line 2 A, C, E,
> ...
> line n F, G
> 
> the problem is that I can not make the split of the comma, so I can not get
> the
> output
>      A B C D E F G O
> [1,] 1 1 1 1 1 0 0 0
> [2,] 1 0 1 0 1 0 0 1
> [n] 0 0 0 0 0 1 1 0

Hi,

hmm, to be honest I didn't get your point yet but let me try.

If you read lines like :

"A, B, C, D, G" etc.

then you can split them by using:

strsplit(line, ', *')
[1] "A" "B" "C" "D" "G"

[', *' is a regular expression to match a "," followed by 0 or more spaces]

Then next issue I see here is that you create num times output matrices in your for loop "for(i in 1:num)" and overwrite the file res.csv all the time. Either you know in beforehand which columns could appear (and how many rows) then you can create your matrix before that loop or you should go with cbind() and rbind() resp. or similar.


Hope that helps a bit,
--Hans


[Rd] strsplit convert data
=?iso-8859-1?Q?Hans-J=F6rg_Bibiko?=