caimiao0714 发表于 2019-1-10 05:49 
你能把你的yaml header贴上来吗?
这是我这个R-markdown文件中所有的内容
---
title: '13433'
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r pressure, echo=FALSE}
x <- as.POSIXct(c('1998-03-16', '2015-11-22'))
c(difftime(x[2],x[1],units = 'days'))+100==6560
x <- as.POSIXct('1998-03-16 13:15:45')
y=as.character(x, format='%H:%M:%S')
y
strsplit(y,':')
as.POSIXct(paste('1991-12', '-01',sep=''),
format='%Y-%m-%d')
x <- as.POSIXct('1998-03-16 13:15:45')
y=as.POSIXlt(x)
y$mon
help(cat)
x <- as.POSIXct(c('1998-03-16', '2015-11-22'))
y=as.POSIXlt(x)
typeof(y)
```
统计软件讲义chapter2练习题
```{r pressure, echo=FALSE}
pa.tab=read.csv('G:\\applied statistics\\统计软件\\patients.csv',header=T)
date1=pa.tab[1:100,'出生日期']
date2 <- pa.tab[1:100,'发病日期']
date3 <- pa.tab[1:100,'诊断日期']
date1ct=as.POSIXct(date1)
date2ct=as.POSIXct(date2)
date1lt=as.POSIXlt(date1ct)
date1lt$year+1900
date2lt=as.POSIXlt(date2ct)
age1=date2lt$year-date1lt$year
birmon=date1lt$mon+1
diseamon=date2lt$mon+1
birday=date1lt$mday
diseaday=date2lt$mday
y=c(which(diseamon>birmon),which(birmon==diseamon&diseaday>=birday))
y
age1
age1[-y]=age1[-y]-1
age1
Sys.setlocale('LC_TIME', 'C')
date2ctfixm=as.character(date2ct,format='%b%y')
date2ctfixm
```
```{r pressure, echo=FALSE}
d.class=read.csv('G:\\applied statistics\\统计软件\\class.csv',header=T)
sex <- d.class[,'sex']
age <- d.class[,'age']
sex
table(sex)
tapply(age,sex,max)
factor(sex,labels = c('F'='女','M'='男'))
```
```{r pressure, echo=FALSE}
A <- matrix(1:6, nrow=3, ncol=2)
apply(A, 1, sum)
t(apply(A, 1, range))
```
```{r pressure, echo=FALSE}
d <- data.frame(name=c(" 李明", " 张聪", " 王建"),age=c(30, 35, 28), height=c(180, 162, 175))
print(d)
d[1:2, c('age', 'height')]
d2 <- as.matrix(d[,c("age", "height")])
d2
```
```{r pressure, echo=FALSE}
d <- data.frame(
group=gl(3, 10, length=30),
subgroup=gl(5,2,length=30),
obs=gl(2,1,length=30))
print(d)
```
P52练习
```{r pressure, echo=FALSE}
d.class=read.csv("G:\\applied statistics\\统计软件\\class.csv",header = T)
d.class[which(d.class[,'age']>=15),] #显示d.class 中年龄至少为15 的行子集;
d.class[which(d.class[,'age']>=15&d.class[,'sex']=='F'),c('name','age')] #显示女生且年龄至少为15 的学生姓名和年龄
x=d.class[,'age']
```
```{r pressure, echo=FALSE}
lm1 <- lm(weight ~ height + age,data=d.class)
```
```{r pressure, echo=FALSE}
sandbox <- function(){
cat(' 沙盘:接连的空行回车可以退出。\n')
browser()
browser()
}
```