Thank you Bert and Peter. My apology for posting poor code. I cannot create a reproducible example of my data, but i hope the list indices as shown below helps you understand my question.. My regex pattern on my previous post works correctly because i tested it on a few sublists and it worked, but did not work for the all lists. I tend to think a set of lapply and one apply function will work, but not sure how to do that.
i tried, but obviously i don't understand nested apply functions. > lapply(mylsit, function(x) gsub(pattern,"",x)) > lapply(mylist, function(x) lapply (x, function(y) gsub(mypattern,"",y))) > lappqaly(mylist, function(x) lapply (x, function(y) > apply(y,2,gsub(mypattern,"",y)))) [[1]] [[1]][[1]] [[1]][[1]][[1]] [[1]][[1]][[2]] [[1]][[1]][[3]] [[1]][[2]] [[1]][[2]][[1]] [[1]][[2]][[2]] [[1]][[3]] [[1]][[3]][[1]] [[1]][[3]][[2]] [[1]][[4]] [[1]][[4]][[1]] [[1]][[4]][[2]] [[1]][[4]][[3]] [[1]][[4]][[4]] [[1]][[4]][[5]] [[1]][[5]] [[1]][[5]][[1]] [[1]][[5]][[2]] [[1]][[5]][[3]] [[1]][[5]][[4]] [[1]][[6]] [[1]][[6]][[1]] [[1]][[6]][[2]] [[1]][[6]][[3]] [[1]][[7]] [[1]][[7]][[1]] [[1]][[7]][[2]] [[1]][[7]][[3]] [[1]][[8]] [[1]][[8]][[1]] [[1]][[8]][[3]] On Thu, Oct 25, 2018 at 9:34 PM Bert Gunter <bgunter.4...@gmail.com> wrote: > > 1. Please learn how to use dput() to provide examples to responders. There's > not much we can do with a text printout (at least without some work that I > don't care to do). > > 2. Do you know what mylist[[c(1,2,1)]] means? If not, read ?(Extract) and > note in particular: > "[[ can be applied recursively to lists, so that if the single index i is a > vector of length p, alist[[i]] is equivalent to alist[[i1]]...[[ip]] > providing all but the final indexing results in a list." > > As your intent is unclear -- no reproducible example showing the desired > result -- I would suggest just using list indexing to access the matrices you > wish to change. But maybe this does not satisfy your vague request. > > Also, something seems screwy in the example you showed: For example, the > [[1]][[2]][[1]] component indicates a 2 x 5 matrix, but I see only 3 columns > of text. Am I missing something? > > Cheers, > Bert > > > > On Thu, Oct 25, 2018 at 6:04 PM Ek Esawi <esaw...@gmail.com> wrote: >> >> Hi All— >> >> I have a list that contains multiple sub-lists and each sub-list >> contains multiple sub(sub-lists), each of the sub(sub-lists) is made >> up of matrices of text. I want to replace some of the text in some >> parts in the matrices on the list. I tried gsub and stringr, >> str_remove, but nothing seems to work >> >> I tried: >> >> lapply(mylist, function(x) lapply(x, function(y) >> gsub("[0-9][0-9]/[0-9[0-9].*com","",y))) >> lapply(mylist, function(x) str_remove(x,"[0-9][0-9]/[0-9[0-9].*com")) >> >> Any help is greatly apprercaited. >> >> >> >> mylist—this is just an example >> >> [[1]] >> [[1]][[1]] >> [[1]][[1]][[1]] >> [,1] [,2] [,3] [,4] [,5] >> [1,] "12/30 12/30" "ABABABABABAB" "8.00" >> [2,] "01/02 01/02" "AAAAAAAAAAAA”. “99" >> [3,] "01/02 01/02" "CACACACACACC” "55.97" >> >> [[1]][[1]][[2]] >> [,1] [,2] >> [1,] "12/30 12/30" "DDDDDDDDDDDDDDD” “29" >> [2,] "12/30 12/30" :GGGGGGGGGGGGGGG” “333” >> >> [[1]][[2]] >> [[1]][[2]][[1]] >> [,1] [,2] [,3] [,4] [,5] >> [1,] "01/02 01/02" "ThankYou" “23” >> [2,] "01/02 01/02" "Standard data" "251" >> >> ______________________________________________ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.