我试图用来grep测试字符串向量是否存在于另一个向量中,并输出存在的值(匹配模式)。 我有一个像这样的数据框: FirstName Letter Alex A1 Alex A6 Alex A7 Bob A1 Chris A9 Chris A6 我在“字母”(Letter)列中有一个字符串模式向量,例如: c("A1", "A9", "A6")。 我想检查模式向量中的任何字符串是否在“字母”列中。如果是的话,我希望输出唯一值。 问题是,我不知道如何使用grep多种模式。我试过了: matches <- unique ( grep("A1| A9 | A6", myfile$Letter, value=TRUE, fixed=TRUE) ) 但这给了我0个匹配,这是不正确的,有什么建议吗?
在R中,一旦数据帧已经初始化,如何将新行添加到数据帧? 到目前为止,我有这个: df <- data.frame("hi", "bye") names(df) <- c("hello", "goodbye") #I am trying to add "hola" and "ciao" as a new row de <- data.frame("hola", "ciao") merge(df, de) # Adds to the same row as new columns # Unfortunately, I couldn't find an rbind() solution that wouldn't give me an …