Search code examples
rcsvcompiler-errorsdimensionsstandard-deviation

I getting an incorrect number of dimensions error while trying to calculate the standard deviation of various rows of a csv file


I have a .csv file whose standard deviations I need to calculate, which contains information for 4 controls and 4 test samples. The file contains over 5000 rows that are data points at different times. As all data are not of the same length, I have truncated the file to the 1st 2500 rows such that there are no N/A values. The code is as follows:

#row means
library(genefilter)
delta = read.csv("/filename.csv", nrows = 2500)

mn1 = rowMeans(delta[,1:4]) # controls
mn2 = rowMeans(delta[,5:8]) # test

s1 = rowSds(mn1[,1:4]) # controls
s2 = rowSds(mn2[,5:8]) # test

The program calculates the mean perfectly, but gives me an error when trying to calculate the standard deviation:

Error in mn1[, 1:4] : incorrect number of dimensions

Help on what is going wrong and how to correct it would be appreciated.

As suggested, here is the file: .csv file


Solution

  • I think the problem is that you calculate the std. deviation from mn1 and mn2 - not from your data. This should work (couldn't install the genefilter package):

    s1 = rowSds(delta[,1:4]) # controls s2 = rowSds(delta[,5:8]) # test