y <- c(1, 2, 3, NA)
is.na(y)

# Recode 99 to missing for the variable age
leadership[age == 99, "age"] <- NA#定义列名称为age的列,此时行值为99的时候为NA
leadership

# Excluding missing values from analyses
x <- c(1, 2, NA, 3)
y <- x[1] + x[2] + x[3] + x[4]
z <- sum(x)
e <- sum(x, na.rm=TRUE)#删除缺失值后运算才能有结果
y;z;e

leadership
newdata <- na.omit(leadership)
newdata

mydates <- as.Date(c("2007-06-22", "2004-02-13"))
str(mydates)
![利用as.Date]函数进行日期格式的转化(https://img.haomeiwen.com/i22546862/ba79a4a4eb5f64f4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
strDates <- c("01/05/1965", "08/16/1975")
class(strDates)
dates <- as.Date(strDates, format = "%m/%d/%Y")
class(dates)

myformat <- "%m/%d/%y"
str(leadership)
leadership$date <- as.Date(leadership$date, myformat)
str(leadership)

today <- Sys.Date()
format(today, format="%B %d %Y")
format(today, format="%A")

startdate <- as.Date("2004-02-13")
enddate <- as.Date("2009-06-22")
enddate - startdate

today <- Sys.Date()
dob <- as.Date("1966-10-12")
difftime(today, dob, units="days")

```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
网友评论