by() error in r: could not find function "FUN"

r, statistics

Solution

This: `t.test(intdiff~orthography)` is not a function. It appears you are expecting `by` to split a dataframe so this might succeed:

by(data, data$speaker, function(d){ t.test(d$intdiff ~ d$orthography, data=d)} )

To explain further: `function(d){ t.test(d$intdiff ~ d$orthography)}` is a function. Or you could try:

by(data, data$speaker,  t.test, form= intdiff ~ orthography ) # untested 

The second version uses t.test (which is a function 'name' rather than a function 'call') and there is a formula method for t.test. The matching with argument names accepts partial names, so the dataframe being passed to``.test` should get automatically matched to the 'data' argument.

Problem

I am trying to apply a t-test to a factor with 24 levels (speaker). My goal is to see if there is a significant difference between orthography (2 levels: jj or L) according to the continuous variable, intensity difference (intdiff). However, when using the by() function, it returned the following error: ``` Error in FUN(X[[1L]], ...) : could not find function "FUN" ``` My syntax which produced the error was: ``` by(data, data$speaker, t.test(intdiff~orthography)) ``` I specified the arguments according to the R documentation, so I can't figure out why it's not accepting the function I provided. Any help would be greatly appreciated. In the event you need to try to reproduce the problem, here is the data set with which I am working: https://www.dropbox.com/s/bxb9ebavln1rh3u/SpanishPalatals.csv Many thanks in advance.

Original source