Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
##物件命名y= 2x+yx-yx*yx/yx^y2*x+3*y^2ls()rm(x)ls()##物件#numeric, 實數向量a <- 49sqrt(a)#sqrt()開根號mode(a)b = c(25,36,49)mode(b)leng...
z = c(x, y)zbb>30 larger.than.30 = b>30rbind(b, larger.than.30)#row(列),橫著排cbind(b, larger.than.30)#column(欄),縱著排 #datafram...
x1 = scan()x2 = scan()scan.failed = scan()getwd()#查詢目前的工作路徑read.table("random.csv")read.table("random.csv",header = TRUE, ...
z#任何含有 NA 資料的運算結果都將是 NA1+NAmax(c(NA, 4, 7))max(c(NA, 4, 7), na.rm=T)#na.rm,移除缺失值#回到 random.csv 資料來看max(random$x3)max(rando...
Upcoming SlideShare
Loading in …5
×

R code 1

411 views

Published on

  • Be the first to comment

R code 1

  1. 1. ##物件命名y= 2x+yx-yx*yx/yx^y2*x+3*y^2ls()rm(x)ls()##物件#numeric, 實數向量a <- 49sqrt(a)#sqrt()開根號mode(a)b = c(25,36,49)mode(b)length(b)#character string, 文字或字串向量, 通常輸入時, 在文字或字串兩側加上雙引號.c <- "my classmate ate my homework"c sub("classmate","dog",c)#sub(對象, 要取代的名稱,資料)#logical, 邏輯變數向量 (true or false), 以 TRUE (T) 或FALSE (F) 呈現,也可以是 1 (T) 與 0 (F)x <- T; y <- F
  2. 2. z = c(x, y)zbb>30 larger.than.30 = b>30rbind(b, larger.than.30)#row(列),橫著排cbind(b, larger.than.30)#column(欄),縱著排 #dataframe,資料欄(長度要相同)data.frame(b, larger.than.30)mydata = data.frame(b, larger.than.30);mydata#使用;在同一行中執行多個完整的指令mydata[1,]#顯示第一列mydata[,2]#顯示第二欄#使用$(錢字號)指定資料欄中的元件)mydata$bmydata$larger.than.30#使用 attach 綁定資料欄CO2#R 內建的資料CO2$uptakeCO2$concuptakeattach(CO2)uptakeconctest##讀取資料#使用 scan()
  3. 3. x1 = scan()x2 = scan()scan.failed = scan()getwd()#查詢目前的工作路徑read.table("random.csv")read.table("random.csv",header = TRUE, sep = ",")random = read.table(file.choose(),header = TRUE, sep = ",")str(random)random random[9,]random$xrandom$yrandom$x3#如未填入資料,則 R 讀取資料時會填入 NA##缺失值 NA, NaN, 與 Null#NA “not available” x <- c(1, 2, 3, NA)x+3#非數字 “Not a number”log(c(0, 1, 2))0/0#infinityInf - Infpi / 0 ## = Inf a non-zero number divided by zerocreates infinity0 / 0 ## = NaN1/0 + 1/0 # Inf1/0 - 1/0 # NaN#null,物件的長度為 0 z = c()
  4. 4. z#任何含有 NA 資料的運算結果都將是 NA1+NAmax(c(NA, 4, 7))max(c(NA, 4, 7), na.rm=T)#na.rm,移除缺失值#回到 random.csv 資料來看max(random$x3)max(random$x3,na.rm=T)mean(random$x3)mean(random$x3,na.rm=T)edit(random)#手動編輯資料,進行一些小修改時很有用randomrandom.modified = edit(random)fix(random)#直接修改資料random#封面的兔子require(onion)data(bunny)p3d(bunny,theta=3,phi=104,box=FALSE)  

×