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 to preserve the "structure" of the original list.  What is a good way to accomplish this?

I tried :

a = matrix(data=c(23,45,'red',78),nrow=2)
b = c('red','green',1,2,3)
d = data.frame( test1=c(223,445,'red',78,56) , test2= c('red',NA,NA,NA,NA) )
e= list(a,b,d)
list1 = list(a,b,d,e)

list2 = lapply(list1,function(list)(gsub("red","green",list)))

str(list1)
str(list2)

but the structue fo the list changed.

       
---------------------------------
Give spam the boot. Take control with tough spam protection

	[[alternative HTML version deleted]]

