Skip to content

a workaround for indexing a function?

3 messages · Adam Kustka, David Winsemius

#
See this?

	`[[alternative HTML version deleted]]`

Means your efforts at including data have been sabotaged by failing to read the Posting guide and send plain text.

Then this line:    median[i] = median(normHL)

Gets you:
Were you under the impression that assignment to an indexed vector with a name would succeed when the vector had not already been pre-defined? R was interpreting that as assignment to an object named 'median' which it was able to find. The error was thrown because the located object is a function (aka closure).

Better would be to chose a more specific object name and not one shared by a regular function. That also means you would have gotten the same error with objects named `df` (the density of the F distribution), `dt` (the t-distribution), `c` (the concatenation function), `C` (the contrasts function), `D` (the derivative function)...... getting the idea that using one or two letter names might be fraught with confusion?

Try using 

 nor_med <- numeric(0)  # before the loop and then in the loop use:

  nor_med[i] = median(normHL)