12
返回列表 发新帖
楼主: pyue
跳转到指定楼层
上一主题 下一主题
收起左侧

datacamp学R

🔗
 楼主| pyue 2019-9-24 12:26:49 | 只看该作者
全局:
Sept.23
introduction&read.csv
utils package
data from flat files, excel, database, web, statistical software
read.csv(“states.csv”,stringsAsFactors=FALSE)
path<-file.path(“~”,”datasets”,”states.csv”)
read.csv(path,stringAsFaxtors=FALSE)
read.delim&read.table
read.delim(“states.csv”,stringsAsFactors=FALSE)
read.table(“ststes2.txt”,header=TRUE,sep=“/”,stringAsFactors=FALSE)
summary()
col.names=c()
colClasses()
read.table is the main function
readr : read_csv&read_tsv
install.packages(“readr”)
library(readr)
read_delim()
read_csv()
read_tsv()
read_delim(“states.txt”,delim=“/”)
col_names() default: TRUE
col_types=“ccdd”  c: character d: double  l:logical
fac<-col_factor(levels=c())
int<-col_integer()
col_types=list(fac,int,int)
skip and n_max
data.table: fread
install.package(“data.table”)
library(data.table)
fread()
fread("path/to/file.txt", drop = 2:4)
fread("path/to/file.txt", select = c(1, 5))
fread("path/to/file.txt", drop = c("b", "c", "d"))
fread("path/to/file.txt", select = c("a", "e"))
plot(x=x轴数据,y=y轴数据,main="标题",sub="子标题",type="线型",xlab="x轴名称",ylab="y轴名称",xlim = c(x轴范围,x轴范围),ylim = c(y轴范围,y轴范围))
                1
plot(x=potatoes$texture,y=potatoes$moistness)
回复

使用道具 举报

🔗
 楼主| pyue 2019-9-25 01:50:32 | 只看该作者
全局:
Sept.24
readxl
different sheets with tabular data
excel_sheets()  list different sheets
read_excel()  actually import data into R
dir()
excel_sheets(“cities.xlsx”)
read_excel(“cities.xlsx”,sheet=2)
read_excel(“”cities.xlsx,sheet=“year_2000”)
col_names=c()
col_type=c(“text”,”blank”)
col_type=NULL
skip=2  n_max is not available
# Print out the first observation from urbanpop_sel
urbanpop_sel[1,]
gdata
read.xls()
xls-csv-r frame
Extend the cbind() call so that it also includes urban_sheet3. Make sure the first column of urban_sheet2 and urban_sheet3 are removed, so you don't have duplicate columns. Store the result in urban.
urban <- cbind(urban_sheet1, urban_sheet2[-1],urban_sheet3[-1])

XLConnect bridge between Excel and R
loadWorkbook()
getSheets()
readWorksheet(loadWorkbook(),sheet=“”)
startRow=
endRow=
startCol=
adapting sheets
createSheet(book,name=“year_2010”)
writeWorksheet(book,pop_2010,sheet=“year_2020)
saveWorkbook(book,file=“cities2.txt”)
renameSheet(book,””,””)
saveWorkbook(book,file=“cities3.xlsx”)
removeSheet(book,sheet=“”)
回复

使用道具 举报

🔗
 楼主| pyue 2019-9-27 01:09:17 | 只看该作者
全局:
Sept.25
connect to a database
what is relational database
how to connect
how to read table
database management system
con<-dbConnect(RMySQL::MySQL(),dbname=,host=,port=,user=,password=)
import table data
dbListTables(con)
dbReadTable(con,”employees”)
dbDisconnect(con)
tables <- lapply(table_names,dbReadTable, conn = con)
SQL Queries from inside R
selective importing
dbGetQuery(con,”SELECT name FROM employees WHERE started_at > “2012-09-01” ”)
products<-dbReadTable(con,”products”)
subset(products,subset=contract==1)
CHAR_LENGTH return the numbers of characters in a string
short<-dbGetQuery(con,"SELECT id,name FROM users WHERE CHAR_LENGTH(name)<5")
SELECT name, post
  FROM users INNER JOIN tweats on users.id = user_id
    WHERE date > "2015-09-19"
res<-dbSendQuery()
dbFetch(res)
while(!dbHasCompleted(res)){chunk<-dbFetch(res,n=1) print(chunk)}
dbClearResult()
HTTP HyperText Transfer Protocol , language of web
read.csv()
read.tsv()
read.csv() is different from read_csv() (need to install read)
HTTPS support since R version 3.2.2
download file
回复

使用道具 举报

🔗
 楼主| pyue 2019-9-27 03:22:10 | 只看该作者
全局:
Sept.26
# Specification of url: url_xls
url_xls <- "http://s3.amazonaws.com/assets.datacamp.com/production/course_1478/datasets/latitude.xls"

# Import the .xls file with gdata: excel_gdata
excel_gdata<-read.xls(url_xls)

# Download file behind URL, name it local_latitude.xls
local_latitude.xls<-download.file(url_xls,destfile="local_latitude.xls")

# Import the local .xls file with readxl: excel_readxl
excel_readxl<-read_excel(local_latitude)

url<-
dest_path<-file.path(“~”,”local_cities.xlsx”)
download.file(url,dest_path)
read_excel(dest_path)
 load data from an RData file using the load()
# Load the httr package
library(httr)

# Get the url, save response to resp
url <- "http://www.example.com/"
resp<-GET(url)

# Print resp
resp

# Get the raw content of resp: raw_content
raw_content<-content(resp,as="raw")

# Print the head of raw_content
print(head(raw_content))

APIs JSON
API Application Programming Interface
jsonlite
fromJSON()
 fromJSON() can convert character strings that represent JSON data into a nicely structured R list.
JSON object    {“id”=1,””}
JSON array   [1,2,3,”kkkk”]
fromJSON(‘[]’)
toJSON()
prettify()
minify()
haven   foreign
SAS Statistics Analysis Software    .sas7bdat    .sas7bcat
STATA statistics and data    .dta
SPSS statistical package for social science    .sax   .por
haven  single argument:path to file   result:R data frame
read_sas()
read_stata()    read_dta()
ontime$Airline<-as.charaactor(as_factor(ontime$Airline))
read_spss()    read_por()    read_sav()
subset(traits,Extroversion>40 & Agreeableness>40)
foreign
read.dta(file,convert.factors=TRUE,convert.dates=TRUE,missing.type=FALSE)
convert.factors convert labelled STATA values to R factors
convert.dates convert STATA dates and times to Date and POSIXct
missing.type if FALSE,convert types of all missing values to NA,if TRUE,store how values are missing in attributes
read.spss(file, use.value.labels=TRUE,to.data.frame=FALSE)
use.value.labels=TRUE  convertt labelled SPSS values to R factors
to.data.frame  return data frame instead of a list
boxplot(a$b)
回复

使用道具 举报

🔗
 楼主| pyue 2019-10-2 04:45:46 | 只看该作者
本楼:
全局:
打卡 oct1
回复

使用道具 举报

🔗
 楼主| pyue 2019-10-15 02:09:16 来自APP | 只看该作者
全局:
Oct14打卡
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表