Ciao:这是我拥有的数据
have = data.frame(c(1,2,3),
c(90,87,71),
c(600,601,602))
colnames(have) <- c("STUDENT","SCORE","TYPE")
这是我想要“想要”的数据
want = data.frame(c(1,1,2,2,3,3),
c(90,90,87,87,71,71),
c(600,600,601,601,602,602),
c(100,101,100,101,100,101))
colnames(want) <- c("STUDENT","SCORE","TYPE","CLASS")
如上图所示,从“拥有”数据开始,我想为每个学生复制该行;添加新列“ CLASS”,对于学生的第一行等于100,对于学生的第二行等于101。
干杯!
答案 0 :(得分:1)
李哲源和Axeman提供了答案
## R core
data.frame(have[rep(1:nrow(have), each = 2), ], CLASS = c(100, 101),
row.names = seq_len(2 * nrow(have)))
## dplyr
dplyr::bind_rows('100' = have, '101' = have, .id = 'CLASS')
答案 1 :(得分:1)
我正在为export abstract class BaseComponent {
protected available: boolean = true;
}
import { BaseComponent } from '../base.component';
export class ComponentA extends BaseComponent implements OnInit {
constructor() {
super();
}
ngOnInit() {
console.log(this.available);
}
}