在下面的 R 代码中,我split
a data.frame
通过一列,一个名为的字符串变量study.name
.
But split
按字母顺序重新订购原来的data.frame
. In BASE R,分割后数据可以保持原来的顺序吗?
D <- read.csv("https://raw.githubusercontent.com/izeh/i/master/k.csv", h = T) # data.frame
m <- split(D, D$study.name)
We can split
by factor
转换后的“study.name”,其中levels
被指定为unique
列的元素和unique
按照唯一元素出现的相同顺序返回值
split(D, factor(D$study.name, levels = unique(D$study.name)))
如果我们需要删除NA
元素,在之前的数据子集split
D1 <- subset(D, !(is.na(study.name)| study.name == ""))
split(D1, factor(D1$study.name, levels = unique(D1$study.name)))
#$Shin.Ellis
# study.name group.name n mpre mpos sdpre sdpos r autoreg t sdif F1 sdp df2 post control outcome ESL prof scope type
#1 Shin.Ellis ME.short 13 0.34 0.72 0.37 0.34 0.5 FALSE NA NA NA NA NA 1 FALSE 1 1 2 1 2
#2 Shin.Ellis ME.long 13 0.34 0.39 0.37 0.36 0.5 TRUE NA NA NA NA NA 2 FALSE 1 1 2 1 2
#3 Shin.Ellis DCF.Short 15 0.37 0.54 0.38 0.36 0.5 FALSE NA NA NA NA NA 1 FALSE 1 1 2 1 2
#4 Shin.Ellis DCF.Long 15 0.37 0.49 0.38 0.36 0.5 TRUE NA NA NA NA NA 2 FALSE 1 1 2 1 2
#5 Shin.Ellis Cont.Short 16 0.32 0.28 0.37 0.36 0.5 FALSE NA NA NA NA NA 1 TRUE 1 1 2 1 2
#6 Shin.Ellis Cont.Long 16 0.32 0.35 0.37 0.32 0.5 TRUE NA NA NA NA NA 2 TRUE 1 1 2 1 2
#$Trus.Hsu
# study.name group.name n mpre mpos sdpre sdpos r autoreg t sdif F1 sdp df2 post control outcome ESL prof scope type
#8 Trus.Hsu Exper 21 0.0799 0.1130 0.0367 0.0472 0.5 FALSE NA NA NA NA NA 1 FALSE 1 2 2 2 1
#9 Trus.Hsu Cont 26 0.0763 0.1095 0.0389 0.0537 0.5 FALSE NA NA NA NA NA 1 TRUE 1 2 2 2 1
#$kabla
# study.name group.name n mpre mpos sdpre sdpos r autoreg t sdif F1 sdp df2 post control outcome ESL prof scope type
#11 kabla ME.short 13 0.34 0.72 0.37 0.34 0.5 FALSE NA NA NA NA NA 1 FALSE 1 1 3 0 1
#12 kabla ME.long 13 0.34 0.39 0.37 0.36 0.5 FALSE NA NA NA NA NA 2 FALSE 1 1 3 0 1
#13 kabla DCF.Short 15 0.37 0.54 0.38 0.36 0.5 FALSE NA NA NA NA NA 1 FALSE 1 1 3 0 1
#14 kabla DCF.Long 15 0.37 0.49 0.38 0.36 0.5 FALSE NA NA NA NA NA 2 FALSE 1 1 3 0 1
#15 kabla Cont.Short 16 0.32 0.28 0.37 0.36 0.5 FALSE NA NA NA NA NA 1 TRUE 1 1 3 0 1
#16 kabla Cont.Long 16 0.32 0.35 0.37 0.32 0.5 FALSE NA NA NA NA NA 2 TRUE 1 1 3 0 1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)