R: how to use user-defined function on my data [closed] - r

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am carrying out data analysis using R but have some problem with coding.
I create my own function for creating frequency table and apply it to variables in my data, but R shows error message.
Could anyone can give me any solution and why it did not work?
> str(diabetes)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 56632 obs. of 30 variables:
$ ID : chr "A308059801" "A308059802" "A308120201" "A308120202" ...
$ year : num 2010 2010 2010 2010 2010 2010 2010 2010 2010 2010 ...
$ region : num 1 1 1 1 1 1 1 1 1 1 ...
$ sex : num 1 2 1 2 2 1 2 1 2 1 ...
$ age : num 61 54 33 33 4 65 59 54 49 18 ...
$ edu : chr "3.000000" "2.000000" "3.000000" "4.000000" ...
$ occp : chr "5.000000" "3.000000" "4.000000" "1.000000" ...
$ marri_1 : 'labelled' num 1 1 1 1 2 1 1 1 1 2 ...
..- attr(*, "label")= chr "Marriage Y/N"
$ marri_2 : 'labelled' num 1 1 1 1 8 1 1 1 1 8 ...
..- attr(*, "label")= chr "Marriage status"
$ tins : 'labelled' num 10 20 10 10 10 20 20 10 10 10 ...
..- attr(*, "label")= chr "Insurance registration"
$ D_1_1 : 'labelled' chr "3.000000" "2.000000" "2.000000" "3.000000" ...
..- attr(*, "label")= chr "Self-report health status"
$ DI1_dg : 'labelled' chr "1.000000" "8.000000" "8.000000" "8.000000" ...
..- attr(*, "label")= chr "HBP diagnosis"
$ DI1_pr : 'labelled' chr "1.000000" "8.000000" "8.000000" "8.000000" ...
..- attr(*, "label")= chr "HBP current status"
$ DI1_pt : 'labelled' chr "1.000000" "8.000000" "8.000000" "8.000000" ...
..- attr(*, "label")= chr "HBP care"
$ DE1_dg : 'labelled' chr "8.000000" "8.000000" "8.000000" "8.000000" ...
..- attr(*, "label")= chr "Diabetes diagnosis"
$ DE1_pr : 'labelled' chr "8.000000" "8.000000" "8.000000" "8.000000" ...
..- attr(*, "label")= chr "Diabetes status"
$ DE1_pt : 'labelled' chr "8.000000" "8.000000" "8.000000" "8.000000" ...
..- attr(*, "label")= chr "Diabetes cure"
$ HE_DMdg : 'labelled' chr "0.000000" "0.000000" "0.000000" "0.000000" ...
..- attr(*, "label")= chr "Diabetes doctor diagnosis"
$ HE_BMI : 'labelled' chr "26.177198" "22.807647" "26.562865" "20.863743" ...
..- attr(*, "label")= chr "BMI"
$ HE_DM : 'labelled' chr "2.000000" "3.000000" "1.000000" "1.000000" ...
..- attr(*, "label")= chr "With diagnosis(over 19 year-old)"
$ LQ4_07 : 'labelled' chr "8.000000" "8.000000" "8.000000" "8.000000" ...
..- attr(*, "label")= chr "Barries for physical activity - diabetes"
$ HE_DMfh1 : 'labelled' chr "0.000000" "0.000000" "9.000000" "1.000000" ...
..- attr(*, "label")= chr "Father with diagnosis"
$ HE_DMfh2 : 'labelled' chr "1.000000" "0.000000" "9.000000" "0.000000" ...
..- attr(*, "label")= chr "Mother with diagnosis"
$ HE_DMfh3 : 'labelled' chr "0.000000" "0.000000" "9.000000" "0.000000" ...
..- attr(*, "label")= chr "Sibling with diagnosis"
$ HE_glu : 'labelled' chr "124.000000" "141.000000" "92.000000" "88.000000" ...
..- attr(*, "label")= chr "Diabetes indicator - glucose level"
$ BE5_1 : 'labelled' chr "1.000000" "1.000000" "1.000000" "1.000000" ...
..- attr(*, "label")= chr "Muscle training frequency"
$ LQ4_04 : 'labelled' chr "8.000000" "8.000000" "8.000000" "8.000000" ...
..- attr(*, "label")= chr "Barriers for physical activity - Have heart disease"
$ DF2_dg : 'labelled' chr "8.000000" "8.000000" "8.000000" "8.000000" ...
..- attr(*, "label")= chr "Diagnosed with depression"
$ HE_IHDfh1: 'labelled' chr "0.000000" "0.000000" "9.000000" "0.000000" ...
..- attr(*, "label")= chr "Diagnosed with Ischaemic heart disease"
$ HE_HP : 'labelled' chr "3.000000" "3.000000" "2.000000" "1.000000" ...
..- attr(*, "label")= chr "Hypertension Status (three levels)"
freq_table <- function (y) {
d <- select (y) %>% group_by (y) %>% summarise (n = n ()) %>% mutate (freq = n / sum (n))
}
lapply(diabetes$marri_1, freq_table)

The select function is at the beginning of the pipe and needs at least two arguments, you can add the name of the dataframe to the argument function
Also, because y is stored in a variable you have to unquote it when using the dplyr verbs by adding !! before it.
library(tidyverse)
# add df as an argument and add it before the select
freq_table <- function (df,y) {
d <- df %>% select (!! y) %>% group_by (!! y) %>% summarise (n = n ()) %>% mutate (freq = n / sum (n))
}
freq_table(diabetes,"marri_1")
Or in a more simple way you can do
tab <- table(diabetes$marri_1)
tab <- as.data.frame(tab)
names(tab) <- c("marri_1","n")
tab$freq <- tab$n /sum(tab$n)
Is this what you were looking for ?

Related

Refer to variable by part of the variable name

It seems that, in R, I can refer to a variable with part of a variable name. But I am confused about why I can do that.
Use the following code as an example:
library(car)
scatterplot(housing ~ total)
house.lm <- lm(housing ~ total)
summary(house.lm)
str(summary(house.lm))
summary(house.lm)$coefficients[2,2]
summary(house.lm)$coe[2,2]
When I print the structure of summary(house.lm), I got the following output:
> str(summary(house.lm))
List of 11
$ call : language lm(formula = housing ~ total)
$ terms :Classes 'terms', 'formula' language housing ~ total
.. ..- attr(*, "variables")= language list(housing, total)
.. ..- attr(*, "factors")= int [1:2, 1] 0 1
.. .. ..- attr(*, "dimnames")=List of 2
.. .. .. ..$ : chr [1:2] "housing" "total"
.. .. .. ..$ : chr "total"
.. ..- attr(*, "term.labels")= chr "total"
.. ..- attr(*, "order")= int 1
.. ..- attr(*, "intercept")= int 1
.. ..- attr(*, "response")= int 1
.. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
.. ..- attr(*, "predvars")= language list(housing, total)
.. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "numeric"
.. .. ..- attr(*, "names")= chr [1:2] "housing" "total"
$ residuals : Named num [1:162] -8.96 -11.43 3.08 8.45 2.2 ...
..- attr(*, "names")= chr [1:162] "1" "2" "3" "4" ...
$ coefficients : num [1:2, 1:4] 28.4523 0.0488 10.2117 0.0103 2.7862 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:2] "(Intercept)" "total"
.. ..$ : chr [1:4] "Estimate" "Std. Error" "t value" "Pr(>|t|)"
$ aliased : Named logi [1:2] FALSE FALSE
..- attr(*, "names")= chr [1:2] "(Intercept)" "total"
$ sigma : num 53.8
$ df : int [1:3] 2 160 2
$ r.squared : num 0.123
$ adj.r.squared: num 0.118
$ fstatistic : Named num [1:3] 22.5 1 160
..- attr(*, "names")= chr [1:3] "value" "numdf" "dendf"
$ cov.unscaled : num [1:2, 1:2] 3.61e-02 -3.31e-05 -3.31e-05 3.67e-08
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:2] "(Intercept)" "total"
.. ..$ : chr [1:2] "(Intercept)" "total"
- attr(*, "class")= chr "summary.lm"
However, it seems that I can refer to the variable coefficients with all of the following commands:
summary(house.lm)$coe[2,2]
summary(house.lm)$coef[2,2]
summary(house.lm)$coeff[2,2]
summary(house.lm)$coeffi[2,2]
summary(house.lm)$coeffic[2,2]
summary(house.lm)$coeffici[2,2]
summary(house.lm)$coefficie[2,2]
summary(house.lm)$coefficien[2,2]
summary(house.lm)$coefficient[2,2]
summary(house.lm)$coefficients[2,2]
They all give the same results: 0.01029709
Therefore, I was wondering when I can refer to a variable with only part of its name in R?
You can do it when rest of name is unambiguous. For example
df <- data.frame(abcd = c(1,2,3), xyz = c(4,5,6), abc = c(5,6,7))
> df$xy
[1] 4 5 6
> df$ab
NULL
> df$x
[1] 4 5 6
df$xy and even df$x gives right data, but df$ab results in NULL because it can refer to both df$abc and df$abcd. It's like when you type df$xy in RStudio and press Ctrl + Space you will get rigtht variable name, so you could refer to part of variable name.
http://adv-r.had.co.nz/Functions.html#lexical-scoping
When calling a function you can specify arguments by position, by
complete name, or by partial name. Arguments are matched first by
exact name (perfect matching), then by prefix matching, and finally by
position.
When you are doing quick coding to analyse some data, using partial names is not a problem, but I tend to agree, it's not good when writing code. In a package you can't do that, R-CMD check will find every occurence.

mapply in R Error "Error in dots[[1L]][[1L]] : object of type 'closure' is not subsettable"

I have this code: mapply(annotate, maxs, s, ann)
Where annotate is a function that takes an annotator object (maxs), a string (s), and an annotated object (ann). s is a list of string and ann an equal-in-length list of annotated objects.
This is the error I am getting:
Error in dots[[1L]][[1L]] : object of type 'closure' is not
subsettable
Info & Code:
s <- c("hello world", "hello world")
require(openNLP)
require(NLP)
require(openNLPmodels.en)
require(tm) #optional
require(hash) #optional
require(openNLPdata) #optional
sent_token_annotator <- Maxent_Sent_Token_Annotator()
word_token_annotator <- Maxent_Word_Token_Annotator()
pos_tag_annotator <- Maxent_POS_Tag_Annotator()
ann <- sapply(s, annotate, list(sent_token_annotator,
word_token_annotator,
pos_tag_annotator))
maxs<-Maxent_Chunk_Annotator(probs = FALSE)
> maxs; str(maxs); s; str(s); ann; str(ann);
An annotator inheriting from classes
Simple_Chunk_Annotator Annotator
with description
Computes chunk annotations using the Apache OpenNLP Maxent chunker employing the default model for language 'en'.
function (s, a)
- attr(*, "meta")=List of 1
..$ description: chr "Computes chunk annotations using the Apache OpenNLP Maxent chunker employing the default model for language 'en'."
- attr(*, "class")= chr [1:2] "Simple_Chunk_Annotator" "Annotator"
[1] "hello world" "hello world"
chr [1:2] "hello world" "hello world"
id type start end features
1 sentence 1 23 constituents=<<integer,4>>
2 word 1 5 POS=UH
3 word 7 11 POS=NN
4 word 13 17 POS=UH
5 word 19 23 POS=NN
List of 5
$ :Classes 'Annotation', 'Span' hidden list of 5
..$ id : int 1
..$ type : chr "sentence"
..$ start : int 1
..$ end : int 23
..$ features:List of 1
.. ..$ :List of 1
.. .. ..$ constituents: int [1:4] 2 3 4 5
..- attr(*, "meta")=List of 2
.. ..$ POS_tagset : chr "en-ptb"
.. ..$ POS_tagset_URL: chr "http://www.comp.leeds.ac.uk/ccalas/tagsets/upenn.html"
$ :Classes 'Annotation', 'Span' hidden list of 5
..$ id : int 2
..$ type : chr "word"
..$ start : int 1
..$ end : int 5
..$ features:List of 1
.. ..$ :List of 1
.. .. ..$ POS: chr "UH"
..- attr(*, "meta")=List of 2
.. ..$ POS_tagset : chr "en-ptb"
.. ..$ POS_tagset_URL: chr "http://www.comp.leeds.ac.uk/ccalas/tagsets/upenn.html"
$ :Classes 'Annotation', 'Span' hidden list of 5
..$ id : int 3
..$ type : chr "word"
..$ start : int 7
..$ end : int 11
..$ features:List of 1
.. ..$ :List of 1
.. .. ..$ POS: chr "NN"
..- attr(*, "meta")=List of 2
.. ..$ POS_tagset : chr "en-ptb"
.. ..$ POS_tagset_URL: chr "http://www.comp.leeds.ac.uk/ccalas/tagsets/upenn.html"
$ :Classes 'Annotation', 'Span' hidden list of 5
..$ id : int 4
..$ type : chr "word"
..$ start : int 13
..$ end : int 17
..$ features:List of 1
.. ..$ :List of 1
.. .. ..$ POS: chr "UH"
..- attr(*, "meta")=List of 2
.. ..$ POS_tagset : chr "en-ptb"
.. ..$ POS_tagset_URL: chr "http://www.comp.leeds.ac.uk/ccalas/tagsets/upenn.html"
$ :Classes 'Annotation', 'Span' hidden list of 5
..$ id : int 5
..$ type : chr "word"
..$ start : int 19
..$ end : int 23
..$ features:List of 1
.. ..$ :List of 1
.. .. ..$ POS: chr "NN"
..- attr(*, "meta")=List of 2
.. ..$ POS_tagset : chr "en-ptb"
.. ..$ POS_tagset_URL: chr "http://www.comp.leeds.ac.uk/ccalas/tagsets/upenn.html"
- attr(*, "class")= chr [1:2] "Annotation" "Span"
- attr(*, "meta")=List of 2
..$ POS_tagset : chr "en-ptb"
..$ POS_tagset_URL: chr "http://www.comp.leeds.ac.uk/ccalas/tagsets/upenn.html"
`
Your help is very appreciated! TY

R haven: missing labels and label names when reading spss file

I'm using the haven package for R to read an spss file with user_na=TRUE. The file has many string variables with value labels. In R only the first of the string variables (SizeofH1) has the correct value labels assigned to it as attribute.
Unfortunately I cannot not even provide a snippet of this data to make this fully reproducible but here is a screenshot of what I can see in PSPP
and what str() in R returns...
$ SizeofH1:Class 'labelled' atomic [1:280109] 3 3 3 3 ...
..- attr(*, "label")= chr "Size of Household ab 2002"
..- attr(*, "format.spss")= chr "A30"
..- attr(*, "labels")= Named chr [1:9] "1" "2" "3" "4" ...
..- attr(*, "names")= chr [1:9] "4 Persons" "2 Persons" "1 Person 50 years plus" "3 Persons" ...
$ PROMOTIO: atomic 40 1 40 40 ...
..- attr(*, "label")= chr "PROMOTION"
..- attr(*, "format.spss")= chr "A30"
$ inFMCGfr: atomic 1 1 1 1 ...
..- attr(*, "label")= chr "in FMCG from2011"
..- attr(*, "format.spss")= chr "A30"
$ TRADESEG: atomic 1 1 1 1 ...
..- attr(*, "label")= chr "TRADE SEGMENT"
..- attr(*, "format.spss")= chr "A30"
$ ORGANISA: atomic 111 111 111 111 ...
..- attr(*, "label")= chr "ORGANISATION"
..- attr(*, "format.spss")= chr "A30"
$ NAME : atomic 9 9 9 9 ...
..- attr(*, "label")= chr "NAME"
..- attr(*, "format.spss")= chr "A30"
I hope someone can point me to any possible reason that causes this behavior.
The "semantics" vignette has some useful information on this topic.
library(haven)
vignette('semantics')
There are a couple of options to get value labels. I think a good one is the example demonstrated below, using the map function from the purrr package (but could be done with lapply instead, too)
# Get data from spss file
df <- read_sav(path_to_file)
# get value labels
df <- map_df(.x = df, .f = function(x) {
if (class(x) == 'labelled') as_factor(x)
else x})
# get column names
colnames(df) <- map(.x = spss_file, .f = function(x) {attr(x, 'label')})
The best is to save your spss file as CSV and then read it in R. I've faced this before and some strings didn't read correctly- Generally SPSS is not very smart when it comes to string variables that this could contribute to the problem.

Understanding how to read nested lists in R in order to access the data

Here is the set up of my list of lists of lists:
please see the development code for the read.GenBank function here
#must be connected to internet for this to work
library(ape)
library(plyr)
gi_sample<-c(336087836, 336087835, 336087834)
#use the read.GenBank function with apply because we ultimately have more than the max at one time (400)
my_output <- apply(gi_sample, 1, function(x) read.GenBank(x))
str(my_output)
List of 3
$ :List of 1
..$ 336087836:Class 'DNAbin' raw [1:606] 00 00 00 00 ...
..- attr(*, "class")= chr "DNAbin"
..- attr(*, "species")= chr "Flavobacterium_johnsoniae"
..- attr(*, "references")=List of 1
.. ..$ 336087836:List of 2
.. .. ..$ :List of 4
.. .. .. ..$ pubmedid: chr(0)
.. .. .. ..$ authors : chr "Rusznyak,A., Akob,D.M., Nietzsche,S., Eusterhues,K., Totsche,K.U., Neu,T.R., Frosch,T., Popp,J., Keiner,R., Geletneky,J., Katzs"| __truncated__
.. .. .. ..$ title : chr "Calcite mineralization by karstic cave bacteria"
.. .. .. ..$ journal : chr "Unpublished"
.. .. ..$ :List of 4
.. .. .. ..$ pubmedid: chr(0)
.. .. .. ..$ authors : chr "Rusznyak,A."
.. .. .. ..$ title : chr "Direct Submission"
.. .. .. ..$ journal : chr "Submitted (13-APR-2011) to the INSDC. Institute of Ecology, Aquatic"
$ :List of 1
..$ 336087835:Class 'DNAbin' raw [1:991] 00 00 00 00 ...
..- attr(*, "class")= chr "DNAbin"
..- attr(*, "species")= chr "Rhodococcus_fascians"
..- attr(*, "references")=List of 1
.. ..$ 336087835:List of 2
.. .. ..$ :List of 4
.. .. .. ..$ pubmedid: chr(0)
.. .. .. ..$ authors : chr "Rusznyak,A., Akob,D.M., Nietzsche,S., Eusterhues,K., Totsche,K.U., Neu,T.R., Frosch,T., Popp,J., Keiner,R., Geletneky,J., Katzs"| __truncated__
.. .. .. ..$ title : chr "Calcite mineralization by karstic cave bacteria"
.. .. .. ..$ journal : chr "Unpublished"
.. .. ..$ :List of 4
.. .. .. ..$ pubmedid: chr(0)
.. .. .. ..$ authors : chr "Rusznyak,A."
.. .. .. ..$ title : chr "Direct Submission"
.. .. .. ..$ journal : chr "Submitted (13-APR-2011) to the INSDC. Institute of Ecology, Aquatic"
$ :List of 1
..$ 336087834:Class 'DNAbin' raw [1:690] 00 00 00 00 ...
..- attr(*, "class")= chr "DNAbin"
..- attr(*, "species")= chr "Serratia_plymuthica"
..- attr(*, "references")=List of 1
.. ..$ 336087834:List of 2
.. .. ..$ :List of 4
.. .. .. ..$ pubmedid: chr(0)
.. .. .. ..$ authors : chr "Rusznyak,A., Akob,D.M., Nietzsche,S., Eusterhues,K., Totsche,K.U., Neu,T.R., Frosch,T., Popp,J., Keiner,R., Geletneky,J., Katzs"| __truncated__
.. .. .. ..$ title : chr "Calcite mineralization by karstic cave bacteria"
.. .. .. ..$ journal : chr "Unpublished"
.. .. ..$ :List of 4
.. .. .. ..$ pubmedid: chr(0)
.. .. .. ..$ authors : chr "Rusznyak,A."
.. .. .. ..$ title : chr "Direct Submission"
.. .. .. ..$ journal : chr "Submitted (13-APR-2011) to the INSDC. Institute of Ecology, Aquatic"
What I would like out of this list:
GI authors title journal
336087836 "Rusznyak,A., Akob,D.M., Nietzsche,S., Eusterhues,K., Totsche,K.U., Neu,T.R., Frosch,T., Popp,J., Keiner,R., Geletneky,J., Katzs"| __truncated__ "Calcite mineralization by karstic cave bacteria" "Unpublished"
336087835 "Rusznyak,A., Akob,D.M., Nietzsche,S., Eusterhues,K., Totsche,K.U., Neu,T.R., Frosch,T., Popp,J., Keiner,R., Geletneky,J., Katzs"| __truncated__ "Calcite mineralization by karstic cave bacteria" "Unpublished"
336087834 "Rusznyak,A., Akob,D.M., Nietzsche,S., Eusterhues,K., Totsche,K.U., Neu,T.R., Frosch,T., Popp,J., Keiner,R., Geletneky,J., Katzs"| __truncated__ "Calcite mineralization by karstic cave bacteria" "Unpublished"
I am sorely in need of an explanation of how these lists are nested. How can I access the "title" and keep the name of each list? I have tinkered with all sorts of "[]" subsetting combinations and ultimately do not understand how to read this list. I have read many beginner explanations, and am still at a loss.
This is changed from the earlier question, although the data remain the same.
Thank you!
It sounds like a dput of the data is very hard to have. I build an example that it might be useful (just an answer because it is too long for comment).
a <- list(list(1:5), list(5:10))
b <- list(list(letters[1:5]), list(LETTERS[5:10]))
data.frame(unlist(a), unlist(b))
unlist.a. unlist.b.
1 1 a
2 2 b
3 3 c
4 4 d
5 5 e
6 5 E
7 6 F
8 7 G
9 8 H
10 9 I
11 10 J
This answer using bind_rows from dplyr should work but I can't test it on your data because you're supplied code doesn't give me a references attribute even with the development version of ape.
library("dplyr")
bind_rows(lapply(seq(refs), function(i) data.frame(GI = names(refs)[i], as.data.frame(refs[[i]][lengths(refs[[i]]) > 0]))))

extracting values from an aovp object in Lmperm

I have the following object M, from which I need to extract the fstatistic. It is a model generated by the function summaryC of a model generated by aovp, both functions from package lmPerm. I have tried hints for extracting values from normal linear models and from the functions in attr, extract and getElement, but without success.
Anybody could give me a hint?
> str(M)
List of 2
$ Error: vegetation: NULL
$ Error: Within :List of 11
..$ NA : NULL
..$ terms :Classes 'terms', 'formula' length 3 Temp ~ depth
.. .. ..- attr(*, "variables")= language list(Temp, depth)
.. .. ..- attr(*, "factors")= int [1:2, 1] 0 1
.. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. ..$ : chr [1:2] "Temp" "depth"
.. .. .. .. ..$ : chr "depth"
.. .. ..- attr(*, "term.labels")= chr "depth"
.. .. ..- attr(*, "order")= int 1
.. .. ..- attr(*, "intercept")= int 1
.. .. ..- attr(*, "response")= int 1
.. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
..$ residuals : Named num [1:498] -46.9 -43.9 -46.9 -38.9 -41.9 ...
.. ..- attr(*, "names")= chr [1:498] "3" "4" "5" "6" ...
..$ coefficients : num [1:4, 1:4] -2.00 -1.00 -1.35e-14 1.00 2.59 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:4] "depth1" "depth2" "depth3" "depth4"
.. .. ..$ : chr [1:4] "Estimate" "Std. Error" "t value" "Pr(>|t|)"
..$ aliased : Named logi [1:4] FALSE FALSE FALSE FALSE
.. ..- attr(*, "names")= chr [1:4] "depth1" "depth2" "depth3" "depth4"
..$ sigma : num 29
..$ df : int [1:3] 4 494 4
..$ r.squared : num 0.00239
..$ adj.r.squared: num -0.00367
..$ **fstatistic** : Named num [1:3] 0.395 3 494
.. ..- attr(*, "names")= chr [1:3] "value" "numdf" "dendf"
..$ cov.unscaled : num [1:4, 1:4] 0.008 -0.002 -0.002 -0.002 -0.002 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:4] "depth1" "depth2" "depth3" "depth4"
.. .. ..$ : chr [1:4] "depth1" "depth2" "depth3" "depth4"
..- attr(*, "class")= chr "summary.lmp"
- attr(*, "class")= chr "listof"
there it goes a reproducible example to play with:
Temp=1:100
depth<- rep( c("1","2","3","4","5"), 100)
vegetation=rep( c("1","2"), 50)
df=data.frame(Temp,depth,vegetation)
M=summaryC(aovp(Temp~depth+Error(vegetation),df, perm=""))
as the str output from your example shows, M is a list of two lists, the second one contains what you want. Hence list extraction via [[ does the trick:
> M[[2]][["fstatistic"]]
value numdf dendf
0.3946 3.0000 494.0000
If this is not what you want, please comment.

Resources