Data Frames : It is a frame of data stored in a two dimensional array which contains row & column
each row pointing a set of value of corresponding column.
# Syntax : data.frame ( vector1 , vector2 , ...... )
Example:
city = c("Delhi" , "Mumbai" , "Chennai" , "Kolkata")
area = c("40 sqKm" , "35 sqKm" , "45 sqKm" , "55 sqKm")
population = c(4500000 , 5000000 , 3500000 , 2800000)
df = data.frame(city , area , population)
print(df)
Output:
city area population
1 Delhi 40 sqKm 4500000
2 Mumbai 35 sqKm 5000000
3 Chennai 45 sqKm 3500000
4 Kolkata 55 sqKm 2800000
1 Delhi 40 sqKm 4500000
2 Mumbai 35 sqKm 5000000
3 Chennai 45 sqKm 3500000
4 Kolkata 55 sqKm 2800000
Accessing the Data Frame
Example:
print(df$city)
print(df$population)
print(df[1])
print(df[ , 1])
print(df[ 1 , ])
print(df['city'])
Manipulating the Data Frame
Example:
df$population = df$population*100
print((df))
# provides summary of the data frame
print(summary(df))
Output:
city area population
1 Delhi 40 sqKm 4.5e+08
2 Mumbai 35 sqKm 5.0e+08
3 Chennai 45 sqKm 3.5e+08
4 Kolkata 55 sqKm 2.8e+08
1 Delhi 40 sqKm 4.5e+08
2 Mumbai 35 sqKm 5.0e+08
3 Chennai 45 sqKm 3.5e+08
4 Kolkata 55 sqKm 2.8e+08
city area population
Chennai:1 35 sqKm:1 Min. :280000000
Delhi :1 40 sqKm:1 1st Qu.:332500000
Kolkata:1 45 sqKm:1 Median :400000000
Mumbai :1 55 sqKm:1 Mean :395000000
3rd Qu.:462500000
Max. :500000000
You may also interested in:
An Introduction to language R
Tutorial # 1.Data Type & Variable Declaration
Tutorial # 2.Operators
Tutorial # 3.Vector & Element Access
Tutorial # 4.Matrix
Tutorial # 5.Data Frame
Tutorial # 2.Operators
Tutorial # 3.Vector & Element Access
Tutorial # 4.Matrix
Tutorial # 5.Data Frame
Tutorial # 6.Arrays
Tutorial # 7.Lists
Tutorial # 8.Factors
Tutorial # 9.Data import
Tutorial # 10.Machine Learning
Tutorial # 11.Visualization
Tutorial # 7.Lists
Tutorial # 8.Factors
Tutorial # 9.Data import
Tutorial # 10.Machine Learning
Tutorial # 11.Visualization
0 Comments