From jorismeys at gmail.com  Tue Oct 25 15:26:10 2011
From: jorismeys at gmail.com (Joris Meys)
Date: Tue, 25 Oct 2011 15:26:10 +0200
Subject: [Rd] strsplit convert data
In-Reply-To: <1319547544761-3936661.post@n4.nabble.com>
References: <1319452277838-3932704.post@n4.nabble.com>
	<1319477336.8217.1.camel@milan>
	<1319495640961-3934808.post@n4.nabble.com>
	<D79B01D9-051E-4833-B155-39B97CAF4AC0@eva.mpg.de>
	<1319547544761-3936661.post@n4.nabble.com>
Message-ID: <CAO1zAVZRDRxn1yKg1zW9SjR2zFK2D5i0WVSp_9PvUcgcNfHB3g@mail.gmail.com>

This is a question for R-Help, not for R-devel by all means. You're
lucky to get an answer, but please use the right channels in the
future.

Cheers
Joris

On Tue, Oct 25, 2011 at 2:59 PM, RMSOPS <ricardosousa2000 at clix.pt> wrote:
> Hello Hans,
>
> Thanks for the reply,
>
> already changed and it gives me the following error
>
> Error in strsplit(line, ",*") : non-character argument
>
> #dataset read file
> dataset
> num<-nrow(dataset)
> num
>
> #results
>> dataset
> ? ?A.B
> 1 A,B,D
> 2 ? F,G
> 3 A,B,E
> 4 ? F,G
> 5 ? E,H
> 6 ? A,E
> 7 ? E,H
> 8 A,B,C
> 9 ? E,H
>> num<-nrow(dataset)
>> num
> [1] 9
>
> #
>
>
> #read lines in the file
> for(i in 1:num)
> {
> ?line<-dataset$Items[i]
> ?print(line)
> ?line<-dataset$Items[i]
> * ?in.s <- strsplit(line, ', *')*
> ?d <- sort (unique (unlist (in.s)))
>
> ?# Create the output matrix
> ?output <- matrix (0, ncol = length (id), nrow = length (in.s))
> ?colNames (output) <- id
>
> ?for (i in seq_along (in.s)) {
> ? ? ?output [i, unlist (in.s [[i]])] <- 1
> ?}
>
> the idea was to create a cycle matrix.
> ?columns have the set of items (A ... B)
> ?rows of the matrix (output) and the value 1 if present and 0 if the line is
> not present.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/strsplit-convert-data-tp3932704p3936661.html
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Mathematical Modelling, Statistics and Bio-Informatics

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



[Rd] strsplit convert data
Joris Meys