Re: [R] function using values separated by a comma

2010-10-18 Thread burgundy
Hi, Thanks again for your help with this. I would like to use a variation of this function in a similar dataset (numeric) with elements separated by a comma e.g. dat - read.table(tc - textConnection( '0,1 1,3 40,10 0,0 20,5 4,2 10,40 10,0 0,11 1,2 120,10 0,0'), sep=) to simply calculate the

Re: [R] function using values separated by a comma

2010-10-18 Thread jim holtman
Try this (I think your result in [2,2] is incorrect): dat - read.table(tc - textConnection( + '0,1 1,3 40,10 0,0 + 20,5 4,2 10,40 10,0 + 0,11 1,2 120,10 0,0'), as.is = TRUE) closeAllConnections() # split the data and create new matrix newDat - lapply(dat, function(.col){ + # split by

Re: [R] function using values separated by a comma

2010-10-11 Thread burgundy
Hi Just used this function on my real data - several enormous files (80 rows by 200 columns...) and it worked perfectly! Thanks again for your help, saved me a lot of time! A last quick query, I have several other similar problems to deal with in my data - do you know a useful book or

[R] function using values separated by a comma

2010-10-08 Thread burgundy
Hello, I have a dataframe (tab separated file) which looks like the example below - two values separated by a comma, and tab separation between each of these. [,1] [,2] [,3] [ ,4] [1,] 0,1 1,3 40,10 0,0 [2,] 20,5 4,2 10,40 10,0 [3,] 0,11 1,2 120,10 0,0 I would like to

Re: [R] function using values separated by a comma

2010-10-08 Thread Joshua Wiley
Hi, It is not the most elegant thing ever, but this does what you want. I am *fairly* certain it generalizes to different sized matrices, but I'd double check. When you divide by 0, it returns NaN, but this is pretty easy to fix if you really want 0s using is.nan(). My general process was:

Re: [R] function using values separated by a comma

2010-10-08 Thread Gabor Grothendieck
On Fri, Oct 8, 2010 at 1:19 AM, burgundy saub...@yahoo.com wrote: Hello, I have a dataframe (tab separated file) which looks like the example below - two values separated by a comma, and tab separation between each of these.     [,1]  [,2]  [,3]  [ ,4] [1,] 0,1  1,3   40,10  0,0 [2,] 20,5

Re: [R] function using values separated by a comma

2010-10-08 Thread Gabor Grothendieck
On Fri, Oct 8, 2010 at 10:18 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Fri, Oct 8, 2010 at 1:19 AM, burgundy saub...@yahoo.com wrote: Hello, I have a dataframe (tab separated file) which looks like the example below - two values separated by a comma, and tab separation between

Re: [R] function using values separated by a comma

2010-10-08 Thread Jeffrey Spies
Here's another method without using any external regular expression libraries: dat - read.table(tc - textConnection( '0,1 1,3 40,10 0,0 20,5 4,2 10,40 10,0 0,11 1,2 120,10 0,0'), sep=) mat - apply(dat, c(1,2), function(x){ temp - as.numeric(unlist(strsplit(x, ',')))