3
votes

I'm trying to import a csv file into R, and I was able to do this by

Lab2x<-read.table("Lab2x.csv").  

From here I'm trying to calculate the average, standard deviation, standard error, t-statistic and the p-value. I was taught to do this using:

xbar <- mean(Lab2x)               # calculate the sample average
sd <- sqrt(var(Lab2x))            # calculate the sample sd
se <- sd/sqrt(12)                 # calculate se of sample average
tstat <- (xbar - 2.27)/se         # calculate the t statistic
pvalue <- 2*(1-pt(abs(tstat),11)) # calculate the p-value

However, when I try to use any of these I get the error:

Warning message: In mean.default(Lab2x) : argument is not numeric or logical: returning NA

What am I doing wrong/missing?

2

2 Answers

3
votes

Lab2x is a list with one or more columns, so the functions expecting a numeric vector will report that they are getting the wrong type of argument. Try substituting Lab2x[[1]] for Lab2x, assuming it is the first column you are interested in.

1
votes

Its hard to tell without seeing your data (try head(Lab2x)).

My advice is to check the data types of Lab2x: read.table constructs a data.frame from the data, and your values are currently being interpreted as character vectors rather than numeric values at the moment. A few problems it could be:

  • A few columns aren't numeric, and the warnings are being thrown there
  • All columns aren't numeric, which means its struggling to find the numbers:
    • Is it reading in the correct number of columns? try read.csv instead.