
R语言
亭午
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
R语言上课代码记录9
# Linear Regressionlibrary("ggplot2")data("mtcars")# plot of dataggplot(data = mtcars) + geom_point(aes(x=wt, y=mpg)) + theme_bw()# linear model mpg = a*wt + b + error# let a = -5, b = 40, then my model becomes mpg = -5*wt + 40 + errorggplot(.原创 2022-05-30 10:22:30 · 554 阅读 · 0 评论 -
R语言代码记录8
setwd("C:/Users/烟雨潇潇/Desktop/大学作业/R语言数据分析")mydata <- read.csv('all_stocks_5yr.csv')mydata1 <- mydata[c('Name','date','close')]colnames(mydata1)[c(2,3)] <- c('Date','Price')AAPL <- mydata1[which(mydata1$Name=='AAPL'),]AAPL <- AAPL[which.原创 2022-05-20 17:01:43 · 351 阅读 · 0 评论 -
R语言代码记录7
# Review SessionCountry <- c('US', 'UK', 'CA', 'CN', 'KR')Year <- seq(2010,2019,by=1)length(Country)GDP <- runif(length(Country)*length(Year), min=0, max=10)# rep(Country, each=length(Year))# rep(Country, length(Year))A <- rep(Country, .原创 2022-05-06 16:49:29 · 201 阅读 · 0 评论 -
R语言上课代码记录6
# Data visualization# Time series# install ggplot2library('ggplot2')attach(economics)mydata <- economicsggplot(data = mydata, mapping = aes(x=date, y=psavert)) + geom_line() + labs(title = 'Personal saving rate', x = 'Year', .原创 2022-04-22 18:38:59 · 331 阅读 · 0 评论 -
R语言上课代码记录5
# loop# For loop# for (variable in sequence){statement} # example 1for(i in c(1:10)) { print(i)}# example 2A <- lettersfor (i in c(1:10)){ cat(A[i],'\n')}# example 3n <- 10for (i in c(n:1)){ cat(rep('*',i), '\n')}# example 4n.原创 2022-04-21 10:49:37 · 386 阅读 · 0 评论 -
R语言上课代码记录4
# A powerful tool in data mining: which()A <- c(10:20)# the which() gives you the position of elements of a # logical vector that Truewhich(A>15)# select the elements in A that are > 15A[which(A >15)]# which.maxwhich.max(A) # the pos.原创 2022-04-08 17:08:56 · 563 阅读 · 0 评论 -
R语言上课代码记录3
# import data# import csv filedata1 <- read.csv("C:/Users/烟雨潇潇/Desktop/大学作业/R语言数据分析/data/co2.csv")# path <- scan("clipboard", what="string")#read.csv(path)# 效果 "C:\\Users\\烟雨潇潇\\Desktop\\大学作业\\R语言数据分析\\data\\co2.csv"# 优快云搜到# import Stata da.原创 2022-04-08 15:23:38 · 323 阅读 · 0 评论 -
R语言上课代码记录2
# vectora <- seq(1,10,2) # rep# random numbersb <- runif(100,min=0,max=1) # uniform distributionc <- rnorm(100,0,2) # normal distribution N(0,4)# listd <- list(a,b,c)# dataframemydata <- data.frame(b,c)# matrixA <- matrix(c.原创 2022-03-26 09:01:35 · 213 阅读 · 0 评论 -
R语言通识课代码记录(1)
# Data structure# vectorID <- c(1:50)print(ID)# seq() functionscore1 <- seq(from=-10, to=10, by=2)score2 <-seq(-10,10, length.out=10)# rep() functionscore3 <- rep("A",50)?repscore4 <- rep(c("A","B","C"), times=10)score5 <- re.原创 2022-03-18 16:52:46 · 225 阅读 · 0 评论