Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8470189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:26:54+00:00 2026-06-10T16:26:54+00:00

I currently use the following code to input a csv file, plot the data

  • 0

I currently use the following code to input a csv file, plot the data points based off one column and store a CpK number to a variable. This code works to calculate the CpK for the entire data set and the graph works as well. I am now looking to calculate the CpK number for each month in the dataset (graphing is not necessary). I looked through the data.table documentation as well as other R documentation, but I having a tough time selecting only the data for each month.

Current Code:(I could have calculated the CpK in one formula, but I have it broken up purposely)

mydf <- read.csv('ID35.csv', header = TRUE, sep=",")
date <- strptime(mydf$DATETIME, "%Y/%m/%d %H:%M:%S")
plot(date,mydf$AVG,xlab='Date',ylab='AVG',main='Data')
abline(h=mydf$MIN,col=3,lty=1)
abline(h=mydf$MAX,col=3,lty=1)
grid(NULL,NULL,col="black")
legend("topright", legend = c(" ", " "), text.width = strwidth("1,000,000"), lty = 1:2, xjust = 1, yjust = 1, title = "Points")
myavg <-mean(mydf$AVG, na.rm=TRUE)
newds <- (mydf$AVG - myavg)^2
newsum <- sum(newds, na.rm=TRUE)
N <- length(mydf$AVG) - 1
newN <- 1/N
total <- newN*newsum
sigma <- total^(1/2)
USL <- mean(mydf$MAX, na.rm=TRUE)
LSL <- mean(mydf$MIN, na.rm=TRUE)
cpk <- min(((USL-myavg)/(3*sigma)),((myavg-LSL)/(3*sigma)))
cpk

Here is what the dataset looks like(date formatting is already done):

mydf(only 24/1000 rows):

Code           DATETIME AVG MIN TARG_AVG MAX
N9 2012/04/10 14:03:37   0.2647     0.22     0.25     0.27
NA 2012/03/30 07:48:17   0.2589     0.22     0.25     0.27
NB 2012/03/24 19:23:08   0.2912     0.22     0.25     0.27
NB 2012/03/25 16:10:17   0.2659     0.22     0.25     0.27
NC 2012/04/10 00:58:29   0.2622     0.22     0.25     0.27
ND 2012/04/14 18:32:52   0.2600     0.22     0.25     0.27
NG 2012/04/21 14:47:47   0.2671     0.22     0.25     0.27
NH 2012/04/09 20:31:17   0.2648     0.22     0.25     0.27
NL 2012/04/24 07:28:17   0.2527     0.22     0.25     0.27
NP 2012/04/23 13:26:50   0.2640     0.22     0.25     0.27
NQ 2012/04/14 20:30:42   0.2590     0.22     0.25     0.27
NS 2012/05/02 09:09:52   0.2651     0.22     0.25     0.27
NU 2012/05/04 13:07:49   0.2688     0.22     0.25     0.27
NV 2012/05/19 23:07:08   0.2716     0.22     0.25     0.27
NX 2012/05/03 02:00:13   0.2670     0.22     0.25     0.27
NY 2012/05/04 12:56:52   0.2680     0.22     0.25     0.27
NZ 2012/05/06 10:05:38   0.2697     0.22     0.25     0.27
O0 2012/05/07 22:01:11   0.2675     0.22     0.25     0.27
O3 2012/06/21 18:09:47   0.2606     0.22     0.25     0.27
04 2012/06/21 18:47:36   0.2545     0.22     0.25     0.27
51 2012/07/24 21:13:08   0.2541     0.22     0.25     0.27
O5 2012/07/26 16:54:09   0.2575     0.22     0.25     0.27
O6 2012/07/20 02:42:29   0.2603     0.22     0.25     0.27
OD 2012/08/25 20:56:55   0.2559     0.22     0.25     0.27
OH 2012/08/28 10:30:11   0.2372     0.22     0.25     0.27

From the table above the only two columns I care about are the DATETIME and the AVG. Once I have the new “myavg” variable for each month I can use the same formula to calculate the CpK number. I am thinking the variable name could be something like’ 2012/08′ I think the code should go something like:

for(each month mydf$DATETIME) (date like 2012/04*,2012/05*)
monthavg <-(mydf$AVG, na.rm=TRUE)

Is there a way to store the CpK number for each month in variables I can access?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:26:56+00:00Added an answer on June 10, 2026 at 4:26 pm
    aggregate(mydf$AVG, list(month=months(as.Date(mydf$DATETIME))), mean)
    
    #    month         x
    # 1  April 0.2618125
    # 2 August 0.2465500
    # 3   July 0.2573000
    # 4   June 0.2575500
    # 5  March 0.2720000
    # 6    May 0.2682429
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently use the following code to position a div directly below an input
Currently I use the following code to retrieve the IP address of the local
Using the following code, we got the error 'Object is currently in use elsewhere'
The Current Setup: So, I can use the following code to save a file
Following situation: I need a container for data with a rowindex. Currently we use
I am in the following predicament, i currently use Subversion for my source control
I'm refactoring a library we currently use, and I'm faced with the following problem.
I am currently playing around with Haskell basics and stumbled upon the following use
I'm trying to use the delegate methods of NSURLConnection. The following methods are currently
I'm starting to use Role Management in my website, and I'm currently following this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.