Re: [R] Convert COLON separated format

2012-10-09 Thread William Dunlap
e wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Noah Silverman > Sent: Monday, October 08, 2012 9:57 PM > To: r-help > Subject: [R] Convert COLON separated format > > I have a bunc

Re: [R] Convert COLON separated format

2012-10-09 Thread jim holtman
If you want something that is fast, read the file in, strip off the colon/data, write it out to a temp and then read it back in. Here is a 355K line file: > temp <- tempfile() > input <- readLines('/temp/colon.txt') > length(input) [1] 355212 > system.time(input <- gsub("(:[0-9]+)", "", input))

Re: [R] Convert COLON separated format

2012-10-08 Thread Rui Barradas
Hello, Here's a function that doesn't do it all but might help. fun <- function(x){ x1 <- unlist(strsplit(x, " ")) x2 <- x1[nchar(x1) > 0] i <- as.integer(x2[1]) x3 <- unlist(strsplit(x2[-1], ":")) j <- as.integer(x3[rep(c(TRUE, FALSE), length(x3)/2)]) y <- numeric(max(j)

Re: [R] Convert COLON separated format

2012-10-08 Thread Hasan Diwan
Mr Silverman, On 9 October 2012 00:56, Noah Silverman wrote: > I have a bunch of data sets that were created for the libsvm tool. They > are in "colon separated sparse format". > Is there a simple way to do this? > Use read.table with a sep of ':' and let me know how you get on. -- H -- Sent

[R] Convert COLON separated format

2012-10-08 Thread Noah Silverman
I have a bunch of data sets that were created for the libsvm tool. They are in "colon separated sparse format". i.e. 1 5:1 27:3 345:10 Is a row with the label of "1" and only has values in columns 5, 27, and 345. I want to read these into a data.frame in R. Is there a simple way to do t