[R] Use R for data aggregation

2013-07-12 Thread nntx
I have a set of evaluation variables (n) for each sample (sample size is large enough) and I am trying to use R (nnet package) to aggregate the data. However, I don't know the weight for each variable (I am sure the weight shouldn't be equally assigned). Specifically, I have 12 indices (CO2, SO2, T

Re: [R] Sending carbon copy mails from R

2013-07-12 Thread Jadhav, Alok
Thanks prof. Ripley. I looked into create.post function. Unfortunately this is not useful in my case. I want to send emails programmatically from a server machine (error notifications etc.) I am able to send emails from my workstation using Outlook com object without any issues. However, on server

Re: [R] Use R for data aggregation

2013-07-12 Thread Jeff Newmiller
This is off-topic here... you are looking for statistical advice, if not problem-domain-specific help. Please read the Posting Guide. --- Jeff NewmillerThe . . Go Live... DCN:

Re: [R] error of betadiver in vegan

2013-07-12 Thread Elaine Kuo
Hello, Thanks for Jari's comment. It worked well after correction. However, an error jumped out for the code below. "Error: cannot allocate vector of size 90.6 Mb" Please kindly advise how to modify it. Thank you. Elaine Code # Non-Passerine table dataNP_1 <-read.dbf("H:/temp_D/stage_4_R_2748/N

Re: [R] calculate time from dates

2013-07-12 Thread Rui Barradas
Hello, It's better if you keep it on the list, the odds of getting more and better answers is greater. As for your question, I've made up a dat2 with an extra column. Try the following, it's independent of the number of columns. dat2 <- data.frame(ID = dat1$ID, month = mondf("01/0

Re: [R] Help with IF command strings

2013-07-12 Thread arun
Hi, Not sure I understand your question. Suppose `data1` is your real data, but if the column names are different, change "V21", "V2" by those in the real data. Based on your initial post, the column names seemed to be the same. mean(data1$V21[data1$V2==1|data1$V2==0]) A.K.  What values woul

Re: [R] Replicating Rows

2013-07-12 Thread arun
Hi, apple<- read.table(text=" Fam.name,Item,AMT.SALE.NET.PROMO,X.CY..QTY.SALE.TOT 9475,Imported Fruits,22110276001,0,436 9499,Imported Fruits,22110277001,0,236 9523,Imported Fruits,22110278001,0,71 ",sep=",",header=TRUE,stringsAsFactors=FALSE) str(apple) #'data.frame':    3 obs. of  4 variables:

Re: [R] Power of Kruskal-Wallis Test?

2013-07-12 Thread Charles Determan Jr
Thank you Greg, However, would you be able to direct me to either an example or further information regarding simulations to measure power? Charles On Thu, Jul 11, 2013 at 4:56 PM, Greg Snow <538...@gmail.com> wrote: > If there were a canned function for power for a non-parametric test, I > wou

[R] readLines() problem-error

2013-07-12 Thread Zsurzsa Laszlo
Hello everyone, I have my program like this: while (length(oneLine <- readLines(con, n = 1, warn = FALSE)) > 0) { # here I process the line I read } The problem is it gives me different output every time. I get a problem/ error like: "Closing unused connection (con)". Sadly I can't provid

Re: [R] Sparse matrix no longer sparse (Matrix Package)

2013-07-12 Thread Doran, Harold
Here is code to completely replicate the issue with comments. I remain confused why simply changing one element of the ddi matrix to be non-integer changes two things: 1) It changes the class of the object I need (A Inverse) and it increases its memory. Ideally, A inverse will remain stored as

Re: [R] Help with installing a .tar.gz package on windows

2013-07-12 Thread Michael Dewey
At 23:49 11/07/2013, Lucy Leigh wrote: Hi everyone, Thanks to everyone for all the advice. I should have been clearer in my first email, the version of 'PReMiuM' I have is not the one available on CRAN at the moment, but a version I was sent by one of the authors, Silvia Liveriani, with a sma

[R] Needing help for excluding vector elements

2013-07-12 Thread Olivier Charansonney
Hello, R for Dummies. How can I exclude the first 1000 values of a vector (length 12000)? More generally all the values up to the ith? Thanks for your help, Dr Olivier Charansonney Cardiologue Centre Hospitalier Sud-Francilien, Corbeil-Essonnes, France [[alternative HTML versi

Re: [R] create new matrix from user-defined function

2013-07-12 Thread bcrombie
Excellent. I should have thought of the with statement, since it’s kind of a universal coding method. Have a good wknd. BNC From: arun kirshna [via R] [mailto:ml-node+s789695n4671365...@n4.nabble.com] Sent: Thursday, July 11, 2013 4:55 PM To: Crombie, Burnette N Subject: Re: create new matrix

[R] What is the maximum limit for an array?

2013-07-12 Thread Jonsson
Hello All, I am having a problem with this: file<-array(dim=c(1440,720,700,3)) Error in array(dim = c(1440, 720, 700, 3)) : 'dim' specifies too large an array I have a memory of 20GB, But I do not know where is the problem!Any help When I replaced 700 by any number bellow like( 600

[R] apply problem

2013-07-12 Thread Amen Alyaari
I will try to explain my problem. There are 600 (global map)files (1440 sample * 720 lines)in two directories dir1 and dir2, which have the same format ,byte,extend,etc. I computed the `bias` between two datasets using the function and code given below as follows: Function: bias <-fun

Re: [R] What is the maximum limit for an array?

2013-07-12 Thread Ben Bolker
Jonsson Bordeaux.inra.fr> writes: > > Hello All, > I am having a problem with this: > > file<-array(dim=c(1440,720,700,3)) > Error in array(dim = c(1440, 720, 700, 3)) : >'dim' specifies too large an array > > I have a memory of 20GB, But I do not know where is the problem!Any h

Re: [R] Needing help for excluding vector elements

2013-07-12 Thread Bert Gunter
Make an effort to learn R. Read "An Introduction to R" -- at least the beginning where you will learn about basic R structures and indexing. Cheers, Bert On Fri, Jul 12, 2013 at 3:06 AM, Olivier Charansonney wrote: > Hello, > > R for Dummies. > > How can I exclude the first 1000 values of a vect

Re: [R] Needing help for excluding vector elements

2013-07-12 Thread Jose Iparraguirre
Dear Olivier, Perhaps you're looking for this? > yourvector[-(1:1000)] Kind regards, José Prof. José Iparraguirre Chief Economist Age UK Age UK Tavis House, 1- 6 Tavistock Square London, WC1H 9NB T 020 303 31482 E jose.iparragui...@ageuk.org.uk Twitter @jose.iparraguirre@ageuk -Origin

Re: [R] Needing help for excluding vector elements

2013-07-12 Thread arun
Hi, Try: set.seed(41) vec1<- sample(1:50,12000,replace=TRUE) tail(vec1,-1000) length(tail(vec1,-1000)) #[1] 11000 A.K. - Original Message - From: Olivier Charansonney To: r-help@r-project.org Cc: Sent: Friday, July 12, 2013 6:06 AM Subject: [R] Needing help for excluding vector elem

Re: [R] readLines() problem-error

2013-07-12 Thread peter dalgaard
It's not really a problem or error, just a message that the system is closing a connection for you. Presumably, you have several previous instances of opening a connection and naming it "con". To avoid the message, just close(con) when you are done reading from it. -pd On Jul 12, 2013, at 15

Re: [R] Standardize GLS coefficients in R

2013-07-12 Thread Greg Snow
One fairly easy option is to just center and scale each of the x-variables, then fit your model on the transformed variables. This works best if your x-variables are roughly symmetric mound shaped and could be meaningless if any of the x-variables is highly skewed or has outliers. On Thu, Jul 11

Re: [R] Help with installing a .tar.gz package on windows

2013-07-12 Thread Duncan Murdoch
On 13-07-12 3:26 PM, Michael Dewey wrote: At 23:49 11/07/2013, Lucy Leigh wrote: Hi everyone, Thanks to everyone for all the advice. I should have been clearer in my first email, the version of 'PReMiuM' I have is not the one available on CRAN at the moment, but a version I was sent by one of

Re: [R] Power of Kruskal-Wallis Test?

2013-07-12 Thread Greg Snow
Here are some examples from the archives: http://tolstoy.newcastle.edu.au/R/e4/help/08/02/2499.html https://stat.ethz.ch/pipermail/r-sig-mixed-models/2009q1/001790.html https://stat.ethz.ch/pipermail/r-sig-mixed-models/2009q1/001819.html On Fri, Jul 12, 2013 at 6:57 AM, Charles Determan Jr w

Re: [R] Help with IF command strings

2013-07-12 Thread arun
Hi, Regarding the 2nd issue of mean=3.8 being "too high", could you explain it. #Using the same example:  dat1$V21[dat1$V2==1|dat1$V2==0] #[1]  6  2  1 10  0  (6+2+1+10+0)/5 #[1] 3.8  mean(dat1$V21[dat1$V2==1|dat1$V2==0]) #[1] 3.8 About missing data: set.seed(55) dat2<- as.data.frame(matrix(sample

Re: [R] Sparse matrix no longer sparse (Matrix Package)

2013-07-12 Thread Doran, Harold
It could be done that way, but when you do the part A %*% D it returns an object of class dsCmatrix. What I see happening here, in plain English is as follows: If you take the inverse of an object of class dsCMatrix, you get in return a matrix of class dgCMatrix. But, if you take the inverse

Re: [R] What is the maximum limit for an array?

2013-07-12 Thread Jonsson
So If download R 3,my problem will be gone? -- View this message in context: http://r.789695.n4.nabble.com/What-is-the-maximum-limit-for-an-array-tp4671395p4671409.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org

Re: [R] error of betadiver in vegan

2013-07-12 Thread David Winsemius
On Jul 12, 2013, at 1:47 AM, Elaine Kuo wrote: > Hello, > > Thanks for Jari's comment. > It worked well after correction. > However, an error jumped out for the code below. > "Error: cannot allocate vector of size 90.6 Mb" > > Please kindly advise how to modify it. Elaine; This problem has li

Re: [R] What is the maximum limit for an array?

2013-07-12 Thread David Winsemius
On Jul 12, 2013, at 6:42 AM, Ben Bolker wrote: > Jonsson Bordeaux.inra.fr> writes: > >> >> Hello All, >> I am having a problem with this: >> >> file<-array(dim=c(1440,720,700,3)) >> Error in array(dim = c(1440, 720, 700, 3)) : >> 'dim' specifies too large an array >> >> I have a

[R] How to determine the pdf of a gamma distribution using the estimated parameters?

2013-07-12 Thread Kaptue Tchuente, Armel
Hello everyone, With th bar histogram (number of occurrences) hist<-c(24,7,4,1,2,1,1) of seven equally spaces classes ]1-4], ]5-8], ]9-12], ]13-16], ]17-20], ]21-24], ]25-28], I obtained shape=0.8276 and rate=0.1448. I would like to know how to build the continuous pdf of a this gamma distri

Re: [R] How to determine the pdf of a gamma distribution using the estimated parameters?

2013-07-12 Thread Ben Bolker
Kaptue Tchuente, Armel sdstate.edu> writes: > [snip] > With th bar histogram (number of occurrences) > hist<-c(24,7,4,1,2,1,1) of seven equally spaces classes > ]1-4], ]5-8], ]9-12], ]13-16], ]17-20], ]21-24], ]25-28], > I obtained shape=0.8276 and rate=0.1448. > > I would like to know how

[R] Upgrade from R 2.11 to R 3.0.1

2013-07-12 Thread Chirag Gupta
Hi I am trying to upgrade R version 2.11 to 3.0.1 on Linux server. I downloaded the latest version it installed correctly. Now when I run R and check the version, it still shows an older version. I am new to Linux. If anyone can tell me how to remove/uninstall R completely from the server, I can t

Re: [R] [XML packages] how to get the sub-node according to the sub-node's attribute?

2013-07-12 Thread Chris Stubben
My question is: Is there a function that can get the sub-node according to the sub-node's attribute ? like that,in the mtcar.xml ,there is sub-node as follow: 30.4 4 95.1 113 3.77 1.513 16.90 1 15 2 I want to get the specific sub-node according to the attribute "id="Lotus Eu

Re: [R] LDA and confidence ellipse

2013-07-12 Thread Lluis
Thanks again -- View this message in context: http://r.789695.n4.nabble.com/LDA-and-confidence-ellipse-tp4671308p4671427.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/l

Re: [R] What is the maximum limit for an array?

2013-07-12 Thread Ben Bolker
Jonsson Bordeaux.inra.fr> writes: > > So If download R 3,my problem will be gone? If you also install it :-) and if you have a 64-bit OS and if you have enough memory to handle the resulting object (see David Winsemius's response). __ R-help@r-pro

Re: [R] Upgrade from R 2.11 to R 3.0.1

2013-07-12 Thread Marc Schwartz
On Jul 12, 2013, at 11:58 AM, Chirag Gupta wrote: > Hi > > I am trying to upgrade R version 2.11 to 3.0.1 on Linux server. > I downloaded the latest version it installed correctly. Now when I run R > and check the version, it still shows an older version. > I am new to Linux. If anyone can tell

[R] How to find the probability of falling in a bivariate ellipse

2013-07-12 Thread Anamika Chaudhuri
Hi All: How would you find out the probability that a point lies within an ellipse? For eg if I was plotting (x,y) for 300 datasets in an 95% ellipsoid region, how do I calculate how many times out of 300 will my points fall inside the ellipse? Heres the code I am using library(MASS) seed<-1234

[R] While using R CMD check: LaTex error: File `inconsolata.sty' not found

2013-07-12 Thread Ravi Varadhan
Hi, While using R CMD check I get the following Latex error message which occurs when creating PDF version of manual: LaTex error: File `inconsolata.sty' not found I am using Windows 7 (64-bit) and R 3.0.1. I have MikTex 2.9. I see that the incosolata.sty is present under \doc\fonts folder. How

Re: [R] How to determine the pdf of a gamma distribution using the estimated parameters?

2013-07-12 Thread Kaptue Tchuente, Armel
Sorry not to be more precise in my previous message. My question is how to use dgamma with the obtained shape and scale parameters in order to approximate the observed pdf since the results of dgamma (seq(4,28,4), shape,rate) are very different from the observed pdf [pdf obs_pdf<-c(0.600, 0.175,

Re: [R] How to determine the pdf of a gamma distribution using the estimated parameters?

2013-07-12 Thread Ben Bolker
On 13-07-12 01:38 PM, Kaptue Tchuente, Armel wrote: > Sorry not to be more precise in my previous message. > My question is how to use dgamma with the obtained shape and scale parameters in order to approximate the observed pdf since the results of dgamma (seq(4,28,4), shape,rate) are very di

Re: [R] While using R CMD check: LaTex error: File `inconsolata.sty' not found

2013-07-12 Thread Berend Hasselman
On 12-07-2013, at 18:04, Ravi Varadhan wrote: > Hi, > While using R CMD check I get the following Latex error message which occurs > when creating PDF version of manual: > LaTex error: File `inconsolata.sty' not found > I am using Windows 7 (64-bit) and R 3.0.1. I have MikTex 2.9. > I see tha

Re: [R] While using R CMD check: LaTex error: File `inconsolata.sty' not found

2013-07-12 Thread David Winsemius
On Jul 12, 2013, at 9:04 AM, Ravi Varadhan wrote: > Hi, > While using R CMD check I get the following Latex error message which occurs > when creating PDF version of manual: > LaTex error: File `inconsolata.sty' not found > I am using Windows 7 (64-bit) and R 3.0.1. I have MikTex 2.9. > I see

Re: [R] While using R CMD check: LaTex error: File `inconsolata.sty' not found

2013-07-12 Thread Berend Hasselman
On 12-07-2013, at 19:49, Berend Hasselman wrote: > > On 12-07-2013, at 18:04, Ravi Varadhan wrote: > >> Hi, >> While using R CMD check I get the following Latex error message which occurs >> when creating PDF version of manual: >> LaTex error: File `inconsolata.sty' not found >> I am using

Re: [R] While using R CMD check: LaTex error: File `inconsolata.sty' not found

2013-07-12 Thread Berend Hasselman
On 12-07-2013, at 18:04, Ravi Varadhan wrote: > Hi, > While using R CMD check I get the following Latex error message which occurs > when creating PDF version of manual: > LaTex error: File `inconsolata.sty' not found > I am using Windows 7 (64-bit) and R 3.0.1. I have MikTex 2.9. > I see tha

[R] simplify a dataframe

2013-07-12 Thread Arnaud Michel
Hello I have the following problem : group the lines of a dataframe when no information change (Matricule, Nom, Sexe, DateNaissance, Contrat, Pays) and when the value of Debut of lines i = value Fin of lines i-1 I can obtain it with a do loop. Is it possible to avoid the loop ? The dataframe

Re: [R] Upgrade from R 2.11 to R 3.0.1

2013-07-12 Thread Marc Schwartz
Chirag, Please keep replies on the list by using 'reply-all'. That way, the responses are available to assist future users in the searchable archives and you also enable others to contribute to the thread. The code below will install R to the default location for a source install, presuming th

Re: [R] simplify a dataframe

2013-07-12 Thread Rui Barradas
Hello, My solution is missing a row, but maybe you can find some inspiration. cols <- c("Matricule", "Nom", "Sexe", "DateNaissance", "contrat", "Pays") irow1 <- duplicated(df1[, cols]) irow2 <- c(FALSE, df1$Debut[-1] == df1$Fin[-nrow(df1)]) df3 <- df1[!irow1 & !irow2, ] dim(df2); dim(df3) #

[R] Optimisation does not optimise!

2013-07-12 Thread Stephen Clark
Hello, I have the following code and data. I am basically trying to select individuals in a sample (by setting some weights) to match known counts for a zone. This is been done by matching gender and age bands. I have tested the function to be optimised and it does behave as I would expect whe

[R] syntactical meaning of fullstop in R functions

2013-07-12 Thread Kay Cichini
hello, what is the meaning of a fullstop in the below R-Ffunction (like in '.GADM') > library(dismo) Lade nötiges Paket: raster Warnmeldungen: 1: Paket ‘dismo’ wurde unter R Version 2.15.3 erstellt 2: Paket ‘raster’ wurde unter R Version 2.15.3 erstellt > getData function (name = "GADM", download

Re: [R] syntactical meaning of fullstop in R functions

2013-07-12 Thread Kay Cichini
just found it myself: in '.GADM' the leading period designates an internal function - the source can be viewed with: getAnywhere('.GADM') 2013/7/12 Kay Cichini > hello, > > what is the meaning of a fullstop in the below R-Ffunction (like in > '.GADM') > > > library(dismo) > Lade nötiges Paket

[R] vegan capscale 'subscript out of bounds' error

2013-07-12 Thread Zhao Jin
Hi list, I am using the capscale function in vegan_2.0-7 to do a constrained principal coordinates analysis, and I kept getting the following error message: Error in Y.r[, oo, drop = FALSE] : subscript out of bounds I googled but I couldn't find an answer. Could anyone tell me why this error msg

[R] replace multiple values in vector at once

2013-07-12 Thread Trevor Davies
I'm trying to find a function that can replace multiple instances of values or characters in a vector in a one step operation. As an example, the vector: x <- c(rep('x',3),rep('y',3),rep('z',3)) > x [1] "x" "x" "x" "y" "y" "y" "z" "z" "z" I would simply like to replace all of the x's with 1's,

Re: [R] replace multiple values in vector at once

2013-07-12 Thread Trevor Davies
I always think that replying to your own r-help feels silly but it's good to close these things out. here's my hack solution: x1<-merge(data.frame(A=x),data.frame(A=c('x','y','z'),B=c(1,2,2)),by='A')[,2] Well that works and should for my more complex situation. If anyone has something a little

Re: [R] create new matrix from user-defined function

2013-07-12 Thread bcrombie
AK, I decided to convert your “with” statement back to index-by-number, and I did look up the ?with help info, but I’m confused about my replacement code below. I got the wrong answer (R didn’t apply the function to my column 1 variable “A_CaseID”). What am I doing wrong? Do I nee

[R] Testing of Diagnostic residuals in R

2013-07-12 Thread ntamjo achille
Hi there,  I want to ask a question about any function in r that helps test residuals of   the vector error correction model. I find it on Pfaff(2008) but he tests only residual for VAR(vector autoregressive model). I need to workout Portmanteau test, Normality test and Heteroskedasticty for

Re: [R] replace multiple values in vector at once

2013-07-12 Thread David Winsemius
On Jul 12, 2013, at 2:56 PM, Trevor Davies wrote: > I always think that replying to your own r-help feels silly but it's good > to close these things out. > > here's my hack solution: > > x1<-merge(data.frame(A=x),data.frame(A=c('x','y','z'),B=c(1,2,2)),by='A')[,2] That fairly tortured compare

Re: [R] replace multiple values in vector at once

2013-07-12 Thread Trevor Davies
Yes, I caught my error once I posted it - I was fiddling with match prior to hammering down with merge but your solution is much better. Thank you. On Fri, Jul 12, 2013 at 3:05 PM, David Winsemius wrote: > > On Jul 12, 2013, at 2:56 PM, Trevor Davies wrote: > > > I always think that replying to

[R] memory problem of betadiver of vegan

2013-07-12 Thread Elaine Kuo
Hello List, This is Elaine. I am running betadiver for a dataset of 4873 rows and 2749 columns. (4873 rows = 4873 gridcell of the study region and 2749 columns for the bird species) The dataset was produced by combing 5 dbf. When running the code o, an error message jumped out, saying "Error: can

Re: [R] replace multiple values in vector at once

2013-07-12 Thread arun
Hi, library(car)  recode(x,"'x'=1;'y'=2;'z'=3") #[1] 1 1 1 2 2 2 3 3 3 #or as.numeric(factor(x)) #[1] 1 1 1 2 2 2 3 3 3 A.K. - Original Message - From: Trevor Davies To: "r-help@r-project.org" Cc: Sent: Friday, July 12, 2013 5:56 PM Subject: Re: [R] replace multiple values in vector

[R] SH test results

2013-07-12 Thread Vahab Pourfaraj
Hi all, I am a phylogenetic student, I'm running SH test to examine free (tree1) and constrained (tree2) trees using R phangorn package. The outputs are like the following and i'm confused how should i interpret them!!!   Trees  ln L           Diff ln L    p-value [1,] 1 -1422.921   0

Re: [R] replace multiple values in vector at once

2013-07-12 Thread Bert Gunter
David is right, but it's trivial if x is a factor (which is the default when you create character columns in a data frame). (Note also how to use rep() properly -- read the docs: ?rep) x <- factor(rep(LETTERS[1:3],e=3)) x [1] A A A B B B C C C Levels: A B C levels(x) <- 1:3 x [1] 1 1 1 2 2 2 3 3

Re: [R] replace multiple values in vector at once

2013-07-12 Thread Law, Jason
In the plyr package there are also the functions revalue and mapvalues: library(plyr) x <- c("a", "b", "c") revalue(x, c(a = "A", c = "C")) mapvalues(x, c("a", "c"), c("A", "C")) mapvalues works on numeric, character and factor. Jason -Original Message- From: r-help-boun...@r-project.or

Re: [R] memory problem of betadiver of vegan

2013-07-12 Thread Elaine Kuo
Hello List, I solved the problem by using the code with 31 votes http://stackoverflow.com/questions/1358003/tricks-to-manage-the-available-memory-in-an-r-session On Sat, Jul 13, 2013 at 6:15 AM, Elaine Kuo wrote: > Hello List, > > This is Elaine. > I am running betadiver for a dataset of 4873

Re: [R] syntactical meaning of fullstop in R functions

2013-07-12 Thread Rolf Turner
On 13/07/13 08:57, Kay Cichini wrote: just found it myself: in '.GADM' the leading period designates an internal function - the source can be viewed with: getAnywhere('.GADM') I think that's a bit misleading. In general, the names of functions (or other objects) which are "internal" to a pac

Re: [R] create new matrix from user-defined function

2013-07-12 Thread arun
Hi, One alternative would be to change colnames: colnames(dat3)<-1:4  data.frame(MW_EEsDue_ERRORS=with(dat3,`1`[`4`!=rowSums(cbind(`2`,`3`))]))   #MW_EEsDue_ERRORS #1 1882 #2 1884 #3 1885 Also, check these: with(dat3,4) #[1] 4  with(dat3,`4`) #[1]   7   9   5

Re: [R] multi-condition summing puzzle

2013-07-12 Thread arun
Hi, May be this helps: dat1<- read.table(text=" ID county date company 1   x  1   comp1 2   y  1   comp3 3   y  2   comp1 4   y  3   comp1 5    x  2  comp2 ",sep="",header=TRUE,stringsAsFactors=FALSE) dat2<- dat1 dat1$answer<-unsplit(lap