[R] extracting numeric values returned when using the by function to run the acf function

Sorkin, John j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Tue May 10 19:29:10 CEST 2022


I am using the by function to run the acf function. Each run of the by function returns more information than I want. All I want is the four values that acf returns, which using the data below would be
1.00  0.15   -0.50  -0.15
How  can I isolate these four values from the output returned by the by function.

Sample code:

RecallSmall <- data.frame(ID=c(1,1,1,1),value=c(6,5,3,4))
cat("Here are the data\n")
RecallSmall
cat("All I want is autocorrerlations, e.g. 1.00  0.15 -0.50 -0.15 \n ")
# attempting to subset does not work at all
by(RecallSmall[1:4,"value"],RecallSmall[1:4,"ID"],acf,na.action=na.pass,plot=FALSE)$acf
# this gives me more than I want, not just the numeric results.
by(RecallSmall[1:4,"value"],RecallSmall[1:4,"ID"],acf,na.action=na.pass,plot=FALSE)

# For your reference, this is what the acf function returns
acf(RecallSmall[1:4,"value"],na.action=na.pass,plot=FALSE)
# For your reference, this is what the acf function returns when the output is subset
acf(RecallSmall[1:4,"value"],na.action=na.pass,plot=FALSE)Thank you, John

Thank you,
John









	[[alternative HTML version deleted]]



More information about the R-help mailing list