日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

R语言空间数据处理(part1)--基础数据操作与处理

發(fā)布時間:2023/12/19 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 R语言空间数据处理(part1)--基础数据操作与处理 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

學習筆記,僅供參考
學習書目:《R語言空間數(shù)據(jù)處理與分析實踐教程》–盧賓賓;


基礎數(shù)據(jù)操作與處理

設置工作路徑,并導入包

workL = "F:/MyStudio/Rstudio/RSpaceMetrology/myRdoc" setwd(workL) #getwd()

函數(shù)學習記錄表


數(shù)據(jù)類型轉(zhuǎn)換

a <- as("123", "numeric") b <- as.numeric("456") class(a) class(b)

match函數(shù)

test1 <- c("A", "A", "B", "B", "B") type_test1 <- unique(test1) print(type_test1) idx <- match(test1, type_test1) print(idx)

which.min和which.max

test2 <- c(9, 4, 7, 2, 9, 5, 3) which.min(test2) which.max(test2)

rev函數(shù)

rev函數(shù)可以實現(xiàn)向量或矩陣的翻轉(zhuǎn);當進行矩陣的翻轉(zhuǎn)時,rev函數(shù)將矩陣當做一個向量處理,矩陣轉(zhuǎn)換為向量的原則以列優(yōu)先

test3 <- c(1:5) print(test3) print(rev(test3)) print("----------------------") test4 <- matrix(1:12, nrow = 3) print(test4) print(rev(test4)) print(matrix(rev(test4), nrow = 3))

用dplyr包中對數(shù)據(jù)進行處理

library(dplyr)data01 <- read.csv("comp.csv") head(data01) #選取Demo列 select(data01, "Dame") %>% head() #選取首字母以B開頭的列 filter(data01, Dame == 0) %>% head() #按照Dame列的大小給data01排序 arrange(data01, Dame) %>% head() #按照Dame列的大小對data01進行降序排序 arrange(data01, desc(Dame)) %>% head()

用rlist包處理關系型數(shù)據(jù)

library(rlist)#創(chuàng)建一個listperson <- list(p1=list(name="Ken",age=24,interest=c("reading","music","movies"),lang=list(r=2,csharp=4,python=3)),p2=list(name="James",age=25,interest=c("sports","music"),lang=list(r=3,java=2,cpp=5)),p3=list(name="Penny",age=24,interest=c("movies","reading"),lang=list(r=1,cpp=4,python=2)))str(person) list.map(person, age) list.map(person, names(lang)) p.age25 <- list.filter(person, age >= 25) str(p.age25) p.py3 <- list.filter(person, lang$python >= 3) str(p.py3)

利用lubridate包處理時間數(shù)據(jù)

library(lubridate)dateString <- c('20131113','120315','12/17/1996','09-01-01') (date <- parse_date_time(dateString, order = c('ymd','mdy','dmy','ymd'))) wday(date[1]) wday(date, label = TRUE) month(date)#查看是否有時間的交疊 begin1 <- ymd_hms("20150903, 12:00:00") end1 <- ymd_hms("20160804, 12:30:00") begin2 <- ymd_hms("20151203, 12:00:00") end2 <- ymd_hms("20160904, 12:30:00") (date_1 <- interval(begin1, end1)) (date_2 <- interval(begin2, end2)) int_overlaps(date_1, date_2)

利用tidyr包進行數(shù)據(jù)處理


library(tidyr)widedata <- data.frame(person=c('Alex','Bob','Cathy'),grade=c(2,3,4),score=c(78,89,88),age=c(18,19,18)) widedata #整合為長數(shù)據(jù) longdata <- gather(widedata, variable, value,-person) longdata#合并 wideunite<-unite(widedata, information, person, grade, score, age, sep= "-") wideunite #拆分 widesep <- separate(wideunite, information,c("person","grade","score","age"), sep = "-") widesep

總結

以上是生活随笔為你收集整理的R语言空间数据处理(part1)--基础数据操作与处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。