0

I was trying to create a new dataset by populating it with a for loop, per this answer. That is the for loop below:

sets = lapply(seq(-97, 99, by = 2), function(x) {
    nums[[1]] = x
    nums
})
stats = matrix(ncol=3, nrow=99)

for(i in 1:99) {
  stats[i] = c(
    sets[i[1]],
    mean(sets[i]),
    median(sets[i])
  )
}

Runtime error:

argument is not numeric or logical: returning NAError in
sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 
  'x' must be atomic

I don't even have a variable named x in the for loop, and I am not trying to sort anything. I jut want to calculate the three values and add them to a row in the dataframe. A similar question was asked here, but the poster was trying to sort something. What could be causing this error?

There was originally a , in stats[i] as in stats[i,]. I removed that but that did not fix the problem.

InterLinked
  • 1,247
  • 2
  • 18
  • 50
  • 2
    "*...and I am not trying to sort anything.*" Yes, you are trying to sort something. Calculating the median requires sorting. – RHertel Jul 12 '18 at 03:56
  • @RHertel If I run median(sets[1]) for example outside the loop that works, so then why would it not work inside the loop? – InterLinked Jul 12 '18 at 13:20

0 Answers0