我有一个来自导入文件的数据帧,如下所示:
stim1.1 <- c(23)
stim1.2 <- c(24)
stim1.3 <-c(266)
stim2.1 <- c(276)
stim2.2 <- c(564)
stim2.3 <-c(250)
mydata <- data.frame(stim1.1, stim1.2, stim1.3, stim2.1, stim2.2, stim2.3)
还有更多的行,但这是大体思路.输出如下:
stim1.1 stim1.2 stim1.3 stim2.1 stim2.2 stim2.3
23 24 266 276 564 250
我正在try 获得类似于以下内容的输出:
stim1 stim2
23 276
24 564
266 250
目前,我正在做以下工作来实现这一点:
mydata <- pivot_longer(mydata, c("stim1.1", "stim1.2", "stim1.3"), values_to = "stim1")
mydata <- pivot_longer(mydata, c("stim2.1", "stim2.2", "stim2.3"), values_to = "stim2")
这是可行的,但对于 Big Data 集来说,它的效率低得令人难以置信.我想有一种更优雅的方式来做这件事,但我不确定那是什么.有什么建议吗?