You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## the plyr package uses **ply() functions, where the first star in the input and the second star is the output. For example, llplyr takes a list in and spits a list out.
# Combining factors acts like interacting two variables. In other words, like interacting two binary variables to create all four possible combinations.
4
+
5
+
# Create a binary variable for treatment or control
# Create two variables of 50 observations, note that we only use 10 month names, because to be combined into a dataset all variables must have the same number of lengths OR be a multiple of the longest length.
4
+
percent.sms<- runif(50)
5
+
state<-state.name
6
+
month<-month.name[1:10]
7
+
8
+
# Create a dataframe of those two variables
9
+
usa<-data.frame(state, percent.sms, month)
10
+
11
+
# Find the number of columns in the data frame
12
+
length(usa)
13
+
14
+
# Select the second and third rows of the first two columns
15
+
usa[2:3, -3]
16
+
17
+
# Select the second and third rows of the first column
18
+
usa[[1]][2:3]
19
+
20
+
# Select the second and third rows of the first column
## POSIXct and POSIXlt are two of three standard date-time classes in R.
4
+
5
+
# POSIXct refers to "calendar time" and stores dates as the number of seconds since the start of 1970. This is best for storing and manipulating dates.
6
+
7
+
## take system time
8
+
now_ct<- Sys.time()
9
+
10
+
## examine the class
11
+
class(now_ct)
12
+
13
+
## see the raw data (notice the second count)
14
+
unclass(now_ct)
15
+
16
+
# POSIXlt stores data as a list with components for seconds, hours, dats, etc. This is best for extracting subparts of a date.
17
+
18
+
## convert to POSIXlt
19
+
now_lt<- as.POSIXlt(now_ct)
20
+
21
+
## examine the class
22
+
class(now_lt)
23
+
24
+
## see the raw data (notice the list)
25
+
unclass(now_lt)
26
+
27
+
# The third date class is Date, and stores the number of day since the start of 1970.
0 commit comments