【发布时间】:2015-04-05 15:06:49
【问题描述】:
这是我遇到的一个典型问题:
replace_letters <- function(string){
gsub("x", "a", string)
}
string_x_new <- replace_letters("string_x")
string_y_new <- replace_letters("strxng_y")
string_z_new <- replace_letters("xstring_z")
...
意思是我正在编写一个函数(示例中的函数是任意的),然后我想将它应用于任意一组对象。有什么更简洁的方法可以做到这一点,而不必多次重复该函数(有时我有 10-15 次针对不同对象调用同一函数的长列表)?
【问题讨论】:
-
为什么对象不在向量中?
-
因为我是菜鸟。想说明一下吗?
-
chartr('x', 'a', strings)在@CactusWoman 的回答中使用strings
标签: r function data-manipulation