forked from GreatKarollo/code_r
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-frames.r
More file actions
25 lines (17 loc) · 706 Bytes
/
data-frames.r
File metadata and controls
25 lines (17 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Data Frames
# 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.
percent.sms <- runif(50)
state <- state.name
month <- month.name[1:10]
# Create a dataframe of those two variables
usa <- data.frame(state, percent.sms, month)
# Find the number of columns in the data frame
length(usa)
# Select the second and third rows of the first two columns
usa[2:3, -3]
# Select the second and third rows of the first column
usa[[1]][2:3]
# Select the second and third rows of the first column
usa$state[2:3]
# Transpose the data frame
usa.t <- t(usa)