From ricardosousa2000 at clix.pt  Tue Oct 25 14:59:04 2011
From: ricardosousa2000 at clix.pt (RMSOPS)
Date: Tue, 25 Oct 2011 05:59:04 -0700 (PDT)
Subject: [Rd] strsplit convert data
In-Reply-To: <D79B01D9-051E-4833-B155-39B97CAF4AC0@eva.mpg.de>
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>
Message-ID: <1319547544761-3936661.post@n4.nabble.com>

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.



[Rd] strsplit convert data
RMSOPS