
R语言是心理与统计学界中最受欢迎的编程语言之一。相比商业统计软件,R语言免费、开源、扩展性强;而相比其他开源编程语言,R的基本操作相对简单,统计与作图模块完善,适合进行统计分析工作。

https://rstudio.github.io/reticulate/
install.packages("reticulate")
https://pypi.org/project/bioread/
library(reticulate)bioread <- import("bioread") # 导入模块acqfile <- bioread$read_file('physio-5.0.1.acq') # 使用bioread中的read_file函数读取文件acqfile # 查看acq文件对象信息# AcqKnowledge file (rev 132): 4 channels, 2000.0 samples/secacqfile$channels # 查看acq文件中的通道# [[1]]# Channel EDA filtered, differentiated: 123787 samples, 2000.0 samples/sec, loaded: True## [[2]]# Channel EKG - ERS100C: 61893 samples, 1000.0 samples/sec, loaded: True## [[3]]# Channel RESP - RSP100C: 241 samples, 3.90625 samples/sec, loaded: True## [[4]]# Channel EDA - GSR100C: 123787 samples, 2000.0 samples/sec, loaded: Trueacqdata1 <- acqfile$channels[[1]]$data # 提取第一个通道中的数据str(acqdata1)# num [1:123787(1d)] -101 -101 -101 -101 -101 ...#可以看到,从Python对象中提取的acqdata1已经是一个R向量了。#因此,之后都可以直接使用R语言对其进行分析#例如:mean(acqdata1)# [1] -110.7604


http://www.rcpp.org/
install.packages("Rcpp")
https://cran.r-project.org/bin/windows/Rtools/index.html
#include <Rcpp.h>using namespace Rcpp;//在函数开始之前的部分,(#include <Rcpp.h>,using namespace Rcpp;,//[[Rcpp::export]])//是C++和Rcpp需要的一些头文件。//如果在RStudio中创建新C++文件,RStudio会自动生成这些头文件。//[[Rcpp::export]]NumericVector add_one(int time) {//这个函数会计算一个向量,其中第一个元素是0,之后每个元素相对上一个元素增加1//注意:C++中的注释开头是“//”//C++中,所有变量的类型和函数返回值的类型都需要主动声明 (例如NumericVector)。//每一句代码要以分号结束//而且数组序号从0开始//NumericVector是Rcpp中的一种数据类型。//使用这种类型,可以保证函数返回值可以被转化成R向量。NumericVector x(time+1);x(0) = 0;for(int i = 1; i <= time; i++){x(i) = x(i-1) + 1;}return x;}
library(Rcpp)sourceCpp("add_one_zh.cpp") #将Rcpp函数导入R中t1<-Sys.time()add_one(100000000) # 运行Rcpp函数t2<-Sys.time()t2-t1 # 计算运行时间# Time difference of 1.545115 secs#相同功能的R函数add_one_slow <- function(x){y <- vector("integer", x+1)y[1] = 0for(i in 1:x+1){y[i] <- y[i-1] + 1}return(y)}t1<-Sys.time()add_one_slow(100000000) # 运行Rcpp函数t2<-Sys.time()t2-t1 # 计算运行时间# Time difference of 18.90944 secs

https://github.com/Sciurus365/RPyCpp
http://adv-r.had.co.nz/Rcpp.html
https://teuder.github.io/rcpp4everyone_en/


文章转载自荷兰心理统计联盟,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




