[Rd] strsplit convert data

2011-10-24 Thread RMSOPS

I am using the following code but I do not know the debug and run for
 correct errors

 library (tcltk)


 file <-tclvalue (tkgetOpenFile ())
   if (nchar (file))
   {
 tkmessageBox ("Select the file")
   }
 else
   {
 tkmessageBox (message = paste ("Was select file", file))
 Dataset <- read.table (file, header = FALSE, sep = "", na.strings =
"NA", dec =".", strip.white = TRUE)
  Dataset
 }

 input <- readLine (Dataset)
 input
 close (Dataset)
 input <- gsub ('*','', input)
 in.s <- strsplit (input, '')
 id <- 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
  }
  
 write.csv (output, file = res.csv)

 Thanks















--
View this message in context: 
http://r.789695.n4.nabble.com/strsplit-convert-data-tp3932704p3932704.html
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] strsplit convert data

2011-10-24 Thread RMSOPS

Hello

   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















--
View this message in context: 
http://r.789695.n4.nabble.com/strsplit-convert-data-tp3932704p3934808.html
Sent from the R devel mailing list archive at Nabble.com.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] strsplit convert data

2011-10-25 Thread RMSOPS
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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel