[R] substitute x for pattern in a list, while preservign list structure. lapply, gsub, list...?

2007-05-16 Thread new ruser
I am experimenting with some of the common r functions. I had a question re:using gsub (or some similar functions) on the contents of a list. I want to design a function that looks at everything contained din a list, and anytime it finds the text string pattern replace it with x. I also wish

Re: [R] substitute x for pattern in a list, while preservign list structure. lapply, gsub, list...?

2007-05-16 Thread Marc Schwartz
On Wed, 2007-05-16 at 09:25 -0700, new ruser wrote: I am experimenting with some of the common r functions. I had a question re:using gsub (or some similar functions) on the contents of a list. I want to design a function that looks at everything contained din a list, and anytime it finds

Re: [R] substitute x for pattern in a list, while preservign list structure. lapply, gsub, list...?

2007-05-16 Thread Gabor Grothendieck
On 5/16/07, Marc Schwartz [EMAIL PROTECTED] wrote: On Wed, 2007-05-16 at 09:25 -0700, new ruser wrote: I am experimenting with some of the common r functions. I had a question re:using gsub (or some similar functions) on the contents of a list. I want to design a function that looks at

Re: [R] substitute x for pattern in a list, while preservign list structure. lapply, gsub, list...?

2007-05-16 Thread Marc Schwartz
On Wed, 2007-05-16 at 13:18 -0400, Gabor Grothendieck wrote: On 5/16/07, Marc Schwartz [EMAIL PROTECTED] wrote: On Wed, 2007-05-16 at 09:25 -0700, new ruser wrote: I am experimenting with some of the common r functions. I had a question re:using gsub (or some similar functions) on the

Re: [R] substitute x for pattern in a list, while preservign list structure. lapply, gsub, list...?

2007-05-16 Thread Gabor Grothendieck
Here is a recursive function you could try. Here f has been defined only to convert character variables. Modify to suit. recurse - function(x, f) { if (length(x) == 0) return(x) if (is.list(x)) for(i in seq_along(x)) x[[i]] - recurse(x[[i]], f) else x - f(x) x } f - function(x) if