I am trying to update a bunch of columns by adding and subtracting SD for each column value. SD for this column.
Below is the reproducible code that I came up with, but I believe that this is not the most efficient way to do this. Can someone suggest me a better way to do this?
Essentially, there are 20 rows and 9 columns. I just need two separate data frames that have values for each column, adjusted by adding the SD of this column, and the other by subtracting SD from each column value.
Hi<-data.frame(replicate(9,sample(0:20,20,rep=TRUE)))
Hi_SD<-apply(Hi,2,sd)
Hi_Matrix<-as.matrix(Hi,rownames.force=FALSE)
Hi_SDValues<-NULL
Hi_SDValues$X1<-Hi_Matrix[,1]+Hi_SD[1]
Hi_SDValues$X2<-Hi_Matrix[,2]+Hi_SD[2]
Hi_SDValues<-as.data.frame(Hi_SDValues)
Hi_SDValues_Less<-NULL
Hi_SDValues_Less$X1<-Hi_Matrix[,1]-Hi_SD[1]
Hi_SDValues_Less$X2<-Hi_Matrix[,2]-Hi_SD[2]
Hi_SDValues_Less<-as.data.frame(Hi_SDValues_Less)
source
share