R 匹配多个重复的名称/字符串
我是R的新手(也是自学成才的),所以请容忍我 我的数据类似于:R 匹配多个重复的名称/字符串,r,string,if-statement,match,R,String,If Statement,Match,我是R的新手(也是自学成才的),所以请容忍我 我的数据类似于: variable value asdf 3 sdfg 2 dfgh 5 fghj 6 ghjk 6 fghj 7 qwer 8 wert 5 erty 2 我需要对所有行的值应用指数函数。但是,变量名等于“asdf”、“wert”或“fghj”的行应保持不变 我已经试着直接做了 if ( (c("asdf", "wert", "fghj")) %in% df$var
variable value
asdf 3
sdfg 2
dfgh 5
fghj 6
ghjk 6
fghj 7
qwer 8
wert 5
erty 2
我需要对所有行的值应用指数函数。但是,变量名等于“asdf”、“wert”或“fghj”的行应保持不变
我已经试着直接做了
if ( (c("asdf", "wert", "fghj")) %in% df$variable {
df$value <- df$value
} else if {
df$value <- exp(df$value)
}
if((c(“asdf”、“wert”、“fghj”))%在%df$变量中{
df$value你可以做什么
totrans <- !(df$variable %in% c("asdf", "wert", "fghj"))
df$value[totrans] <- exp(df$value[totrans])
totrans我想你可能想要ifelse
。特别是df
totrans <- !(df$variable %in% c("asdf", "wert", "fghj"))
df$value[totrans] <- exp(df$value[totrans])
df$value <- ifelse(df$variable %in% c("asdf", "wert", "fghj"),
df$value, exp(df$value))