Course
Data Frames
Convert a List to a DataframeCreate an Empty DataframeCombine Two Dataframe into OneChange Column Name of a DataframeExtract Columns From a DataframeDrop Columns in a DataframeReorder Columns in a DataframeSplit DataframeMerge Multiple DataframesDelete Rows From DataframeMake a List of DataframesIntroduction
"Hello World" ProgramAdd Two VectorsFind Sum, Mean and Product of Vector in R ProgrammingTake Input From UserGenerate Random Number from Standard DistributionsSample from a PopulationFind Minimum and MaximumSort a VectorStrings
Concatenate Two StringsFind the Length of a StringCheck if Characters are Present in a StringExtract n Characters From a StringReplace Characters in a StringCompare two StringsConvert Factors to CharactersTrim Leading and Trailing WhitespacesVectors
Concatenate a Vector of StringsCheck if a Vector Contains the Given ElementCount the Number of Elements in a VectorFind Index of an Element in a VectorAccess Values in a VectorAdd Leading Zeros to VectorR Program to Delete Rows From Dataframe
Example 1: Delete Single Row of Dataframe in R
# Create a data frame
dataframe1 <- data.frame (
Name = c("Juan", "Alcaraz", "Simantha"),
Age = c(22, 15, 19),
Address = c("Nepal", "USA", "Germany")
)
# delete 1st row
print(dataframe1[-1, ])
# extract 1st and 3rd row
print(dataframe1[-c(1,3), ])
Output
Name Age Address
2 Alcaraz 15 USA
3 Simantha 19 Germany
In the above example, we have created a dataframe named dataframe1. And we have deleted a row using the index value and -
sign.
Here, dataframe1[-1, ]
deletes entire elements of 1st row
Example 2: Split Dataframe by Column Names in R
# Create a data frame
dataframe1 <- data.frame (
Name = c("Juan", "Alcaraz", "Simantha"),
Age = c(22, 15, 19),
Address = c("Nepal", "USA", "Germany")
)
# delete 1st and 3rd row
print(dataframe1[-c(1,3), ])
Output
Name Age Address
2 Alcaraz 15 USA
Here, dataframe1[-c(1,3), ]
deletes entire elements of 1st and 3rd row.