我是R的新手(我已经尝试过搜索;对不起,如果在其他地方重复这一点!)我需要一些帮助!我正在尝试编辑data.frame中的行名称:
我从几个vcf文件开始,使用UIApplication.shared.keyWindow?.rootViewController?.view
创建列表列表,然后使用func popoverController(controller: UIViewController) {
let nc = UINavigationController(rootViewController: controller)
UIUtils.setMainNavigationBar(nav: (nc.navigationBar))
nc.modalPresentationStyle = .popover
let popover = nc.popoverPresentationController!
controller.preferredContentSize = CGSize(width: 548, height: 532)
popover.delegate = self
popover.permittedArrowDirections = .init(rawValue: 0)
let window = UIApplication.shared.keyWindow!
let root = UIApplication.shared.keyWindow?.rootViewController?.view
popover.sourceView = root
popover.sourceRect = CGRect(x: window.bounds.width / 2, y: window.bounds.height / 2, width: 0, height: 0)
UIApplication.shared.keyWindow?.rootViewController?.present(nc, animated: true, completion: {
let _ = Utils.returnSideMenuRootVC()
UIApplication.shared.keyWindow?.rootViewController?.view.addSubview(self.overlay.darkOverlay())
})
}
func prepareForPopoverPresentation(_ popoverPresentationController: UIPopoverPresentationController) {
}
func popoverPresentationController(_ popoverPresentationController: UIPopoverPresentationController, willRepositionPopoverTo rect: UnsafeMutablePointer<CGRect>, in view: AutoreleasingUnsafeMutablePointer<UIView>) {
let x = popoverPresentationController.presentingViewController.view.center
let newRect = CGRect(x: x.x, y: x.y, width: 0, height: 0)
rect.initialize(to: newRect)
}
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
removeBackground()
return true
}
func popoverPresentationControllerDidDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) {
}
展平列表,并将提取的指标合并到数据帧中,但最终得到以下内容:
lapply()
而我需要的是
unlist()
有什么建议吗?提前致谢!
答案 0 :(得分:1)
建议是:将该信息存储在一个额外的变量中。您不能在数据框中存储非唯一的rownames:
df <- data.frame(
A = 1:3,
B = 3:1
)
rownames(df) <- c("D","E","D")
给出:
Error in `row.names<-.data.frame`(`*tmp*`, value = value) :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique value when setting 'row.names': ‘D’
所以你可以这样做:
mydataframe$origin <- gsub("\\d_(S\\d{1})_.+", "\\1", rownames(mydataframe))
但你无法将其设为rownames。
答案 1 :(得分:0)
我会用:
library(stringr)
str_extract(row.names(mydataframe),"S[0-9]")
答案 2 :(得分:0)
或者,使用gsub和群组捕获:
Arrange