I want to extract the X-squared value and p-value (number only) from three string vectors.
smr.text1
[1] ""
[2] "\tPearson's Chi-squared test with Yates' continuity correction"
[3] ""
[4] "data: data$parasite and data$T1"
[5] "X-squared = 0.017361, df = 1, p-value = 0.8952"
[6] ""
smr.txt2
[1] ""
[2] "\tPearson's Chi-squared test with Yates' continuity correction"
[3] ""
[4] "data: data$parasite and data$T2"
[5] "X-squared = 2.5679e-32, df = 1, p-value = 1"
[6] ""
smr.text3
[1] ""
[2] "\tPearson's Chi-squared test with Yates' continuity correction"
[3] ""
[4] "data: data$parasite and data$T3"
[5] "X-squared = 0.17857, df = 1, p-value = 0.6726"
[6] ""
It was easy for me to extract those values from the first string vector using indexing numbers:
> c1 <- as.numeric(str_sub(smr.txt1[5], 13, 20))
> c1
[1] 0.017361
> p1 <- as.numeric(str_sub(smr.txt1[5], -6))
> p1
[1] 0.8952
But in the second string vector I can't really do the same since it's a scientific number. Also I could do the same with the third string vector, but is there a better way, for example using a loop to extract these values only and put them in the same data frame? Thanks in advance!