4

I try to conduct a t.test, but it gives me such a mistake.
Error using t.test() in R

not enough 'x' observations

The data has only numerical values, no NA. The ratio of groups is 10 to 35. How can this be circumvented? Thanks in advance for the help!

t.test(data$Vrajdeb[data$a=="1"],data$Vrajdeb[data$a=="2"])

reference to data https://1drv.ms/x/s!ApJwAUaohJFdr1ID-QebKTmE_o3K

Diana Bugrimova
  • 71
  • 1
  • 1
  • 5
  • 3
    Please provide a sample data. You can find here an example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – DJV May 27 '18 at 20:57
  • 2
    That is the error you get with just 1 observation, `t.test` works with a vector of length equal to 2 or greater. What is the output of `length(data$Vrajdeb[data$a=="1"])`? – Rui Barradas May 27 '18 at 21:05
  • length(data$Vrajdeb[data$a=="1"]) [1] 0 – Diana Bugrimova May 27 '18 at 21:09
  • I think there is some encoding issue with your data: `a` is not really an `a` – user20650 May 27 '18 at 22:12
  • yup file gets imported with first column as Unicode: for character 'a', use an index 1 for your column 'a' or rename it as `colnames(data)[1] <- 'a'` – Mankind_008 May 27 '18 at 23:40

2 Answers2

1

You have enough observations but you are not able to subset your data based on column 'a'. This is due to your data getting imported with first column name as Unicode: <U+430> for character 'a', use an index 1 for your column 'a' or rename it as

colnames(data)[1] <- 'a'

Then run the t test.

Mankind_008
  • 2,158
  • 2
  • 9
  • 15
0

Here is one way to do it. Note that when I loaded your data in, the column labeled a turns up as X.:

library(dplyr)
library(broom)
> data
# A tibble: 45 x 25
      X. Cinizm Agres Vrajdeb Zavisim Motiv Stimul  Igra Rasslab Podderjka_1
   <int>  <int> <int>   <int>   <int> <int>  <int> <int>   <int>       <int>
 1     1     33    22      17       1     7      6     7      13          15
 2     1     54    38      24       3     8     13     4      13           8
 3     1     44    35      21       6     8     11    10      14           6
...

> data %>% do(tidy(t.test(Vrajdeb~X., data=.)))
   estimate estimate1 estimate2  statistic   p.value parameter  conf.low 
conf.high  method alternative
1 -1.728571      17.3  19.02857 -0.8999865 0.3819658  15.42225 -5.812628  
2.355486 Welch Two Sample t-test   two.sided
mysteRious
  • 4,102
  • 2
  • 16
  • 36