我试图在每组数据之后添加一行NA R.
之前已经提出类似的问题.在每组数据后插入一个空行.
在这种情况下,接受的答案也可以如下工作.
group <- c("a","b","b","c","c","c","d","d","d","d")
xvalue <- c(16:25)
yvalue <- c(1:10)
df <- data.frame(cbind(group,xvalue,yvalue))
df_new <- as.data.frame(lapply(df, as.character), stringsAsFactors = FALSE)
head(do.call(rbind, by(df_new, df$group, rbind, NA)), -1 )
group xvalue yvalue
a.1 a 16 1
a.2 <NA> <NA> <NA>
b.2 b 17 2
b.3 b 18 3
b.31 <NA> <NA> <NA>
c.4 c 19 4
c.5 c 20 5
c.6 c 21 6
c.41 <NA> <NA> <NA>
d.7 d 22 7
d.8 d 23 8 …Run Code Online (Sandbox Code Playgroud) 我在下面创建了一个与excel中的表格类似的示例表,它应该用于说明问题.我想在column1中的每个不同数据之后添加一行(最简单的方法,使用excel,谢谢).
_
column1 | column2 | column3
----------------------------------
A | small | blue
A | small | orange
A | small | yellow
B | med | yellow
B | med | blue
C | large | green
D | large | green
D | small | pink
Run Code Online (Sandbox Code Playgroud)
_
注意:每个不同列1后面的空行
column1 | column2 | column3
----------------------------------
A | small | blue
A | small | orange
A | small | yellow
B | med | yellow
B …Run Code Online (Sandbox Code Playgroud) 我需要一些帮助来找到一种在每“x”行之后将单个空行添加到数据帧中的 baseR 方法。有人知道我该怎么做吗?任何帮助将不胜感激..谢谢。
例如,如果 x = 64,则在数据框中每 64 行后添加一个空行