R语言
亭午
这个作者很懒,什么都没留下…
展开
-
R语言上课代码记录9
# Linear Regression library("ggplot2") data("mtcars") # plot of data ggplot(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 + error ggplot(.原创 2022-05-30 10:22:30 · 489 阅读 · 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 · 317 阅读 · 0 评论 -
R语言代码记录7
# Review Session Country <- 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 · 162 阅读 · 0 评论 -
R语言上课代码记录6
# Data visualization # Time series # install ggplot2 library('ggplot2') attach(economics) mydata <- economics ggplot(data = mydata, mapping = aes(x=date, y=psavert)) + geom_line() + labs(title = 'Personal saving rate', x = 'Year', .原创 2022-04-22 18:38:59 · 283 阅读 · 0 评论 -
R语言上课代码记录5
# loop # For loop # for (variable in sequence){statement} # example 1 for(i in c(1:10)) { print(i) } # example 2 A <- letters for (i in c(1:10)){ cat(A[i],'\n') } # example 3 n <- 10 for (i in c(n:1)){ cat(rep('*',i), '\n') } # example 4 n.原创 2022-04-21 10:49:37 · 345 阅读 · 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 True which(A>15) # select the elements in A that are > 15 A[which(A >15)] # which.max which.max(A) # the pos.原创 2022-04-08 17:08:56 · 526 阅读 · 0 评论 -
R语言上课代码记录3
# import data # import csv file data1 <- read.csv("C:/Users/烟雨潇潇/Desktop/大学作业/R语言数据分析/data/co2.csv") # path <- scan("clipboard", what="string") #read.csv(path) # 效果 "C:\\Users\\烟雨潇潇\\Desktop\\大学作业\\R语言数据分析\\data\\co2.csv" # CSDN搜到 # import Stata da.原创 2022-04-08 15:23:38 · 285 阅读 · 0 评论 -
R语言上课代码记录2
# vector a <- seq(1,10,2) # rep # random numbers b <- runif(100,min=0,max=1) # uniform distribution c <- rnorm(100,0,2) # normal distribution N(0,4) # list d <- list(a,b,c) # dataframe mydata <- data.frame(b,c) # matrix A <- matrix(c.原创 2022-03-26 09:01:35 · 164 阅读 · 0 评论 -
R语言通识课代码记录(1)
# Data structure # vector ID <- c(1:50) print(ID) # seq() function score1 <- seq(from=-10, to=10, by=2) score2 <-seq(-10,10, length.out=10) # rep() function score3 <- rep("A",50) ?rep score4 <- rep(c("A","B","C"), times=10) score5 <- re.原创 2022-03-18 16:52:46 · 185 阅读 · 0 评论