Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>All standard variants of t-test use sample variances in their formulas, and you cannot compute that from one observation as you are dividing with n-1, where n is sample size.</p> <p>This would probably be the easiest modification, although I cannot test it as you did not provide sample data (you could <code>dput</code> your data to your question):</p> <pre><code> t&lt;- lapply(1:length(x), function(i){ if(length(x[[i]][[2]])&gt;1){ t.test(dat$Value,x[[i]][[2]]) } else "Only one observation in subset" #or NA or something else }) </code></pre> <p>Another option would be to modify the indices which are used in <code>lapply</code>:</p> <pre><code>ind&lt;-which(sapply(x,function(i) length(i[[2]])&gt;1)) t&lt;- lapply(ind, function(i) t.test(dat$Value,x[[i]][[2]])) </code></pre> <p>Here's an example of the first case with artificial data:</p> <pre><code>x&lt;-list(a=cbind(1:5,rnorm(5)),b=cbind(1,rnorm(1)),c=cbind(1:3,rnorm(3))) y&lt;-rnorm(20) t&lt;- lapply(1:length(x), function(i){ if(length(x[[i]][,2])&gt;1){ #note the indexing x[[i]][,2] t.test(y,x[[i]][,2]) } else "Only one observation in subset" }) t [[1]] Welch Two Sample t-test data: y and x[[i]][, 2] t = -0.4695, df = 16.019, p-value = 0.645 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -1.2143180 0.7739393 sample estimates: mean of x mean of y 0.1863028 0.4064921 [[2]] [1] "Only one observation in subset" [[3]] Welch Two Sample t-test data: y and x[[i]][, 2] t = -0.6213, df = 3.081, p-value = 0.5774 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -3.013287 2.016666 sample estimates: mean of x mean of y 0.1863028 0.6846135 Welch Two Sample t-test data: y and x[[i]][, 2] t = 5.2969, df = 10.261, p-value = 0.0003202 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 3.068071 7.496963 sample estimates: mean of x mean of y 5.5000000 0.2174829 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload