简体   繁体   English

向量化陈述式中的R求和

[英]R summing in vectorized statements

I have the following statement. 我有以下声明。 I seem to have to repeat myself by writing out the numbers myself. 我似乎不得不自己写下数字来重复自己。 Using seq(-1,-9,-1) or -1:-9 doesn't seem to work. 使用seq(-1,-9,-1)或-1:-9似乎不起作用。 Is there another way to speak with R? 还有其他与R交谈的方式吗?

difnormsum<-rowSums(data.frame(difnorm[[1]][-nrow(difnorm)],difnorm[[1]][-1], 
difnorm[[1]][-2],difnorm[[1]][-3],difnorm[[1]][-4],difnorm[[1]][-5],
difnorm[[1]][-6],difnorm[[1]][-7],difnorm[[1]][-8],difnorm[[1]][-9]))

You could try 你可以试试

 rowSums(data.frame(
     lapply(c(nrow(difnorm),1:9), function(i) difnorm[[1]][-i])
 ))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM