getwd()
txt<-read.table("test.txt",header = FALSE,sep = "",skip = 7)
head(txt)
getwd()
txt<-scan("test.txt",what = "",sep = "",na.strings = "NA",skip = 7)
txt
scan()比read.table效率更好
C#调用R脚本
1.安装R.NET
2.using RDotNet;
3.调用r脚本
REngine.SetEnvironmentVariables();
REngine engine = REngine.GetInstance();
engine.Initialize();
engine.Evaluate("source('C:/Users/JackChen/Desktop/test.r')");
engine.Dispose();
4.r脚本示例
setwd("c://")
jpeg(file="test123.jpeg")
plot(1:10,main = "主标题",sub="子标题",xlab="x轴标题",ylab="y轴标题",col="red",col.main='red')
#rect(1, 5, 3, 7, col="red")
dev.off()
R语言连接Sql Server数据库
#Windows身份验证
install.packages("RODBC")
library(RODBC)
conStr <- odbcDriverConnect('driver={SQL Server};server=(local);database=ForecastDataSystem;trusted_connection=true')
sql<-sqlQuery(conStr,"select top 100* from Weather_H_SpiData")
print(sql)
#Sql Server身份验证
install.packages("RODBC")
library(RODBC)
conStr <- odbcDriverConnect('driver={SQL Server};server=10.10.10.20;database=ForecastDataSystem;uid=Develop;pwd=Develop;')
sql<-sqlQuery(conStr,"select top 100* from City")
print(sql)