I have data that looks like this.
And I want to find the maximum and minimum densities
given the list of standard deviations (SD) and means (MEAN) below:
info0 info1 info2 SD Mean
10x 0 e0 0.38 1.14
10x 0 e2 0.74 1.48
10x 0 e4 1 1.85
10x 0 e6 1.24 2.27
10x 0.1 e0 0.35 1.13
10x 0.1 e2 0.69 1.44
10x 0.1 e4 0.96 1.82
10x 0.1 e6 1.21 2.23
10x 0.5 e0 0.34 1.12
10x 0.5 e2 0.67 1.4
10x 0.5 e4 0.95 1.75
10x 0.5 e6 1.19 2.17
10x 1 e0 0.29 1.09
10x 1 e2 0.59 1.32
10x 1 e4 0.87 1.66
10x 1 e6 1.11 2.06
10x 2 e0 0.23 1.06
10x 2 e2 0.5 1.24
10x 2 e4 0.79 1.54
10x 2 e6 1.04 1.9
10x 4 e0 0.22 1.0.5
10x 4 e2 0.41 1.15
10x 4 e4 0.65 1.37
10x 4 e6 0.91 1.7
I tried this but fail.
dat <- read.table("test.dat", header = TRUE)
densities <- apply(dat[, 4:5], 1, function(x) rnorm(n = 1000000, mean = x[2], sd = x[1]))
maxden <- max(densities)
minden <- min(densities)
What’s the right way to do it?
Let me first suggest that you not operate on such a huge data set and such a large number of
nin thernorm. This makes it easy to throw abrowserin the code and figure out what’s happening. First the means in your data is a factor because of something you did with formatting.That has to be addressed in the code.
Now we can see use the code to get what we want (you’ll have to adjust the n in rnorm and supply more rows to the code when you actually use it but for testing purposes this was ideal):