[Rd] strsplit convert data
Milan Bouchet-Valat
nalimilan at club.fr
Mon Oct 24 19:28:55 CEST 2011
Le lundi 24 octobre 2011 à 03:31 -0700, RMSOPS a écrit :
> 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)
Hm, that code triggers many errors. What's the problem you'd like help
on? You can't reasonably expect people to fix all of your code... ;-)
More information about the R-devel
mailing list