[R] lapply and paste

Sarah Goslee sarah.goslee at gmail.com
Wed Mar 28 20:50:47 CEST 2012


suff isn't a list, so lapply() isn't the right choice. How about instead:

> suff<- c("C1", "C2", "C3")
> sapply(suff, function(x)paste("filename_", x, ".ext", sep=""))
               C1                C2                C3
"filename_C1.ext" "filename_C2.ext" "filename_C3.ext"


On Wed, Mar 28, 2012 at 2:31 PM, Ed Siefker <ebs15242 at gmail.com> wrote:
> I have a list of suffixes I want to turn into file names with extensions.
>
> suff<- c("C1", "C2", "C3")
> paste("filename_", suff[[1]], ".ext", sep="")
> [1] "filename_C1.ext"
>
> How do I use lapply() on that call to paste()?
> What's the right way to do this:
>
> filenames <-  lapply(suff, paste, ...)
>
> ?
>
> Can I have lapply() reorder the arguments to FUN?
>



-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list