I have a data.frame called d
. In this data.frame, some columns consist of constant numbers across the rows of the first column: study.name
(see below).
For example, columns ESL
, ESL.1
, prof
, and prof.1
are constant numbers for all rows of Shin.Ellis
and also constant for all rows of Trus.Hsu
and so on.
Q: In BASE R, how can I separate such constant variables, and then condense them to one row with only one number?
My desired output is shown further below. A functional answer is appreciated.
d <- read.csv("https://raw.githubusercontent.com/izeh/m/master/irr.csv", h = T)[-(2:3)]
## FIRST 8 ROWS:
# study.name ESL prof scope type ESL.1 prof.1 scope.1 type.1
# 1 Shin.Ellis 1 2 1 1 1 2 1 1
# 2 Shin.Ellis 1 2 1 1 1 2 1 1
# 3 Shin.Ellis 1 2 1 2 1 2 1 1
# 4 Shin.Ellis 1 2 1 2 1 2 1 1
# 5 Shin.Ellis 1 2 NA NA 1 2 NA NA
# 6 Shin.Ellis 1 2 NA NA 1 2 NA NA
# 7 Trus.Hsu 2 2 2 1 2 2 1 1
# 8 Trus.Hsu 2 2 NA NA 2 2 NA NA
Desired output:
# study.name ESL prof ESL.1 prof.1
# 1 Shin.Ellis 1 2 1 2
# 2 Trus.Hsu 2 2 2 2
# . . . . . . # AND SO ON !!!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…