Data Frames: Nptel Noc18-Cs28
Data Frames: Nptel Noc18-Cs28
Data frames
In this lecture
Dataframe
Create
Access rows and columns
Edit
Add new rows and columns
Subset
subset() which extracts subset of data based on conditions
Editing dataframes
Dataframes can be edited by direct assignment
Code
Console Output
# Introduction to dataframes
vec1 = c(1,2,3)
vec2 = c("R","Scilab","Java")
vec3 = c("For prototyping", "For
prototyping","For Scaleup")
df = data.frame(vec1,vec2,vec3)
print(df)
df[[2]][2] = “R”
Editing dataframes
• A dataframe can also be edited using the edit() command
• Create an instance of data frame and use edit command to open a
table editor, changes can be manually made
Code
# Editing a data frame
myTable = data.frame()
myTable = edit(myTable)
# continuing from previous example A ‘-’ sign before value and before ‘,’
for rows & after ‘,’ for columns
# Deleting rows and columns:
‘!’ means no to those rows /columns
df2 = df[-3,-1] which satisfy the condition
print(df2)
# conditional deletion:
df3 = df[,!names(df) %in% c(“vec3”)]
print(df3)
df4 = df[!df$vec1==3,]
print(df4)