Not able to identify confidence level using ci.confidence

Below is my data set in CSV
Name Age
Sudira,23
Suas,28
Sumi,26
Suresh,29
Rakesh,53
Ravi,22
Roshan,30
Raghu,27
Srikanth,35
Guru|,23

I am trying to find confidence interval using ci(x,confidence=0.95). I am getting below error
Error in UseMethod("ci") :
no applicable method for 'ci' applied to an object of class "data.frame"
Pkg :gmodels has been installed

Code :
a<-read.csv(file = "path.csv",head = TRUE, sep = ",")
attach(a)
a.new<-a[2]
names(a.new)
b<-a.new
ci(b,confidence=0.95)

Can you please let me know what mistake I have done and why I am getting above error ?

What package does the ci() function come from?

gmodels::ci() calculates confidence intervals for model estimates, and I believe you want to estimate a confidence interval for the population mean, so you can try using something like this.

df <- data.frame(stringsAsFactors=FALSE,
           Name = c("Sudira", "Suas", "Sumi", "Suresh", "Rakesh", "Ravi",
                    "Roshan", "Raghu", "Srikanth", "Guru|"),
           Age = c(23, 28, 26, 29, 53, 22, 30, 27, 35, 23)
)
t.test(df$Age, conf.level = 0.95)$"conf.int"
#> [1] 23.09414 36.10586
#> attr(,"conf.level")
#> [1] 0.95

Created on 2019-08-06 by the reprex package (v0.3.0.9000)

If it's the gmodels::ci() function, then you need to pass it a numeric vector.

a.new <- a[2] creates a new data.frame with just the second column from a. In general, single-bracket subsetting will return an object with the same class. I.e., class(a) is the same as class(a[2]).

To extract a single component, use double-bracket subsetting: a[[2]].

Also, it's often better to use names instead of numeric indices. It makes the code less brittle when data is rearranged, and easier to read: a[["Age"]].

gmodels is the pkg name

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.