我想用相同长度的字符串向量的相应元素替换逻辑向量中的TRUE
的任何实例。
例如,我想结合一下:
my_logical <- c(TRUE, FALSE, TRUE)
my_string <- c("A", "B", "C")
产生:
c("A", "", "C")
我知道:
my_string[my_logical]
给予:
"A" "C"
,但似乎无法弄清楚如何返回相同长度的向量。我的第一个想法是将向量简单地相乘,但这会引起错误“二进制运算符的非数字参数”。
答案 0 :(得分:3)
带有replace
replace(my_string, !my_logical, "")
#[1] "A" "" "C"
答案 1 :(得分:2)
那又怎么样:
my_logical <- c(TRUE, FALSE, TRUE)
my_string <- c("A", "B", "C")
my_replace <- ifelse(my_logical==TRUE,my_string,'')
my_replace
[1] "A" "" "C"
编辑,谢谢@www:
ifelse(my_logical, my_string, "")
答案 2 :(得分:1)
当ifelse
等于NA
时使用my_logical
添加FALSE
(否则为TRUE
)。使用此子集。
new <- my_string[ifelse(!my_logical, NA, T)]
new
[1] "A" NA "C"
如果您想让""
超过NA
,请继续执行此操作。
new[is.na(new)] <- ""
[1] "A" "" "C"
答案 3 :(得分:1)
也许:
<property>
<name>plugin.includes</name>
<value>protocol-(selenium|http)|urlfilter-(regex|validator)|parse-(html|tika)|index-(basic|anchor)|indexer-solr|scoring-opic|urlnormalizer-(pass|regex|basic)</value>
<description>Regular expression naming plugin directory names to
include. Any plugin not matching this expression is excluded.
In any case you need at least include the nutch-extensionpoints plugin. By
default Nutch includes crawling just HTML and plain text via HTTP,
and basic indexing and search plugins. In order to use HTTPS please enable
protocol-httpclient, but be aware of possible intermittent problems with the
underlying commons-httpclient library. Set parsefilter-naivebayes for classification based focused crawler.
</description>
</property>
<property>
<name>selenium.driver</name>
<value>firefox</value>
<description>
A String value representing the flavour of Selenium
WebDriver() to use. Currently the following options
exist - 'firefox', 'chrome', 'safari', 'opera', 'phantomjs' and 'remote'.
If 'remote' is used it is essential to also set correct properties for
'selenium.hub.port', 'selenium.hub.path', 'selenium.hub.host',
'selenium.hub.protocol', 'selenium.grid.driver' and 'selenium.grid.binary'.
</description>
</property>
当然,这会覆盖现有对象。