## list()列表
```{r}
findwords <- function(tf){ #tf short for:text file
txt <- scan(tf,"") #读取文本文件,空格间隔的英文内容,汉字不适用
print(txt) #输出文本列表
wl <- list() #创建word(单词)列表list --wl
for (i in 1:length(txt)){ # 循环读取txt内单词
wrd <- txt[i]
wl[[wrd]] <- c(wl[[wrd]],i) # wl[[wrd]是个单词位置,把位置向量存起来
}
return(wl)
}
#orders the output of findwords() by word frequwncy
freqwl <- function(wordlist){
freqs <- sapply(wordlist,length)
return(wordlist[order(freqs)]) #order()按位次排序,sort() 按值排序
}
x <- findwords("tf.txt")
# names(x) #显示列表标签名,提取x中的单词
# unlisted(x) #获取列表的值
# unname(x) #去掉列表元素名
#sort(names(x)) #列表标签名(单词)排序
#提取词频较高的10%单词作图
#----------------------------
snyt <- freqwl(x)
nword <- length(snyt)
freqs <- sapply(snyt[round(0.9*nword):nword],length)
barplot(freqs)
```
## 列表应用lapply() & sapply()
```{r}
lapply(list(1:6,20:36),median) #输出中位数1:6,20:36列表
sapply(list(1:6,20:36),median) #输出中位数1:6,20:36矩阵
分类: R语言
-
R语言list()应用
-
不同自由度t分布图、聚类分析举例
不同自由的的t分布图
par(mfrow=c(2,2)) #opar=par(no.readonly = TRUE) y=seq(-4,4,length.out=100) par(fig=c(0,1,0,1)) plot(y,dt(y,1),type = "l",ylim = c(0,0.5)) plot(y,dt(y,3),type = "l",ylim=c(0,0.5)) plot(y,dt(y,5),type = "l",ylim=c(0,0.5)) plot(y,dt(y,10),type = "l",ylim=c(0,0.5)) plot(y,dt(y,30),type = "l",ylim=c(0,0.5))Cluster聚类分析
means <- sample(c(-3,0,3),replace = T) x <- rnorm(99,mean = means) d <- dist(x) hc <- hclust(d) plot(hc,hang=-1) clust <- cutree(hc,k=3) plot(x~factor(clust),main = "分类均值") -
R数据框-行列求和方法
widgets <- c(179,153,183,153,154) gadgets <- c(167,193,190,161,181) thingys <- c(182,166,170,171,186) daily.prod <- data.frame(widgets,gadgets,thingys,row.names = c('Mon','Tue','Wed','Thu','Fri')) rbind(daily.prod,Total=colSums(daily.prod)) cbind(daily.prod,Totol=rowSums(daily.prod)) -
AOV 数据准备–单因素方差分析(stack函数)
stack函数将列表合并为一个两列数据框,该数据框的列名称分别为:values,ind第一列包含数据,第二列包含平行因子-即一个分组变量。
v1 <- c(0.60,0.35,0.44,.62,.60)
v2 <- c(.70,.601,.63,.87,.85,.70,.64)
v3 <- c(.76,.71,.92,.87)
comb <- stack(list(v1=v1,v2=v2,v3=v3)) #向量列表标签不能省略,用做平行因子水平
print(comb)
aov(values~ind,comb)
summary(aov(values~ind,data=comb)) -
Swirl Courses Organized by Title
A Advanced R Programming by Roger Peng
C ConoceR by David Duncan
D Data Science and R by Wush Wu Daten einlesen und kennenlernen by RLab-Team Daten visualisieren mit ggplot2 by RLab-Team Deskriptive Statistik Gelaendeklimatologie by RLab-Team Deskriptive Statistik mit bodenkundlichen Daten by RLab-Team Deskriptive Statistik und Vergleiche meteorologischer Zeitreihen by RLab-Team
E
Einfuehrung in Datenaufbereitung mit tidyR by RLab-Team
Einfuehrung in Datenhandling und Visualisieren von Klimadaten by RLab-Team
Exploratory Data Analysis by Team swirl
G
Getting and Cleaning Data by Team swirl Google Forms Course by Sean Kross
M
MARSYS Data analysis with R by RLab-Team MARSYS Statistik und Programmierung mit R by RLab-Team
P
Programacion Estadistica R by Ismael Fernández Programando en R by José R Sosa
Q
qss-swirl by Kosuke Imai
R
R-Grundlagen by RLab-Team R Programming by Team swirl
R Programmieren by Stephan Weibelzahl
The R Programming Environment by Roger Peng
Regular Expressions by Jon Calder
Regression Models by Team swirl
S
Statistical Inference by Team swirl
V
A (Very) Short Introduction to R by Claudia Brauer
Advanced R Programming
Author Roger Peng Co-Authors Brooke Anderson Sean Kross Description The second course in the Mastering Software Development in R series.
Installation
swirl::install_course("Advanced R Programming")Manual Installation Download this file. Run swirl::install_course() in the R console. Select the file you just downloaded. Website https://github.com/swirldev/Advanced_R_Programming
-
jamovi这款统计软件不错吆
https://www.jamovi.org/
https://mp.weixin.qq.com/s/SE-VZcweyfNrLC1VAo68NA(1)它免费。
(2)它基于R语言上进行创作的,开源,能够利用许多R包来进行分析。
(3)如果你修改了数据,统计分析结果实时更新。
(4)SPSS 统计分析与结果分离的界面实在令人不爽,它则整合在一起,大屏时代数据库和分析一起显示,不美么?
(5)它直接导出三线表!!!这恐怕是初学者最大的痛点之一了。
(6)关键是它的操作如此简单,一键出结果,太适合小白了
-
R、python绘图网
The R Graph Gallery – Help and inspiration for R charts (r-graph-gallery.com)
Example:
Library
library(fmsb)
Create data: note in High school for Jonathan:
data <- as.data.frame(matrix( sample( 2:20 , 10 , replace=T) , ncol=10))
colnames(data) <- c(” 数学” , “english” , “biology” , “music” , “R-coding”, “data-viz” , “french” , “physic”, “statistic”, “sport” )To use the fmsb package, I have to add 2 lines to the dataframe: the max and min of each topic to show on the plot!
data <- rbind(rep(20,10) , rep(0,10) , data)
Check your data, it has to look like this!
head(data)
The default radar chart
radarchart(data)
-
R 书籍网
网址: bookdown.org
Write HTML, PDF, ePub, and Kindle books with R Markdown,and put it in bookdown.org
-
学习R的网站
网站非常全面,实用简洁 ;https://www.statmethods.net/index.html