假设一个data.frame:
df <- structure(list(Dates = structure(1:2, .Label = c("2017-05-02",
"2017-07-30"), class = "factor"), Var1 = c(1, 2), X1 = c(3, 4
), X2 = c(5, 6), Var2 = c(7, 8), X3 = c(9, 10), X4 = c(11, 12
)), class = "data.frame", row.names = c(NA, -2L))
看起来像这样:
Dates Var1 X1 X2 Var2 X3 X4
1 2017-05-02 1 3 5 7 9 11
2 2017-07-30 2 4 6 8 10 12
是否可以将已知的姓氏扩展为连续的姓氏?因此,它看起来像:
Dates Var1 Var1 Var1 Var2 Var2 Var2
1 2017-05-02 1 3 5 7 9 11
2 2017-07-30 2 4 6 8 10 12
实际数据帧要大得多,带有更多已知和未知变量,因此首选自动方法。
答案 0 :(得分:1)
假设您想重命名以“ X”开头的列,我们可以用replace
NA
将它们na.locf
然后使用library(zoo)
names(df) <- na.locf(replace(names(df), grepl("^X", names(df)), NA))
df
# Dates Var1 Var1 Var1 Var2 Var2 Var2
#1 2017-05-02 1 3 5 7 9 11
#2 2017-07-30 2 4 6 8 10 12
来获取该列的先前名称。
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
{
if(section == tableView.numberOfSections - 1)
{
let footerView = UIView.init(frame: CGRect(x:0, y:0, width:tableView.frame.size.width, height:100))
footerView.backgroundColor = UIColor.clear
let imageView: UIImageView = UIImageView.init(frame: CGRect.init(x: 40, y: 0, width: footerView.frame.size.width - 80, height: 100))
imageView.image = #imageLiteral(resourceName: "google_logo")// google logo image
imageView.contentMode = UIViewContentMode.scaleAspectFit
footerView.addSubview(imageView)
return footerView
}
else
{
return nil
}
}