library(tidyverse)
## Registered S3 methods overwritten by 'ggplot2':
## method from
## [.quosures rlang
## c.quosures rlang
## print.quosures rlang
## -- Attaching packages -------------------------------------- tidyverse 1.2.1 --
## <U+221A> ggplot2 3.1.1 <U+221A> purrr 0.3.2
## <U+221A> tibble 2.1.1 <U+221A> dplyr 0.8.1
## <U+221A> tidyr 0.8.3 <U+221A> stringr 1.4.0
## <U+221A> readr 1.3.1 <U+221A> forcats 0.4.0
## -- Conflicts ----------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
start_k=tibble(e1=c(1, 2, 3), p1=c(2, 3, 5),
e2=c(1, 2, 3), p2=c(3, 1, 2))
tabel<- sapply(1:2, function(nr){
enimi <- paste("e", nr, sep="")
pnimi <- paste("p", nr, sep="")
tt <- cor.test(as.numeric(start_k[[enimi]]), as.numeric(start_k[[pnimi]]))
c(nr, tt$estimate %>% unname(), tt$p.value)
})
tabel %>% t() %>% as_tibble() %>% rename(jnr=V1, cor=V2, p=V3)
## Warning: `as_tibble.matrix()` requires a matrix with column names or a `.name_repair` argument. Using compatibility `.name_repair`.
## This warning is displayed once per session.
## # A tibble: 2 x 3
## jnr cor p
## <dbl> <dbl> <dbl>
## 1 1 0.982 0.121
## 2 2 -0.5 0.667