0% found this document useful (0 votes)
96 views7 pages

Data Frames in R

A data frame in R is a two-dimensional data structure that can store data in tabular format, with rows and columns containing different data types. A data frame is created using the data.frame() function by specifying vectors for each column. Columns within a data frame can be accessed using [[]], $ operators, or [ ] which returns a data frame. Data frames can be combined vertically with rbind() and horizontally with cbind(), ensuring column names match when combining vertically. The length() and summary() functions provide information about a data frame.

Uploaded by

Namya Priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views7 pages

Data Frames in R

A data frame in R is a two-dimensional data structure that can store data in tabular format, with rows and columns containing different data types. A data frame is created using the data.frame() function by specifying vectors for each column. Columns within a data frame can be accessed using [[]], $ operators, or [ ] which returns a data frame. Data frames can be combined vertically with rbind() and horizontally with cbind(), ensuring column names match when combining vertically. The length() and summary() functions provide information about a data frame.

Uploaded by

Namya Priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

DATA FRAMES IN

R
Program - 7

Prof. Namyapriya Dayananda, Asst Professor, CSE, KSIT BCS358B


R Data Frame
■ A data frame is a two-dimensional data structure which can store data in tabular format.
■ Data frames have rows and columns and each column can be a different vector. And
different vectors can be of different data types.
■ Before we learn about Data Frames, make sure you know about R vector.

Prof. Namyapriya Dayananda, Asst Professor, CSE, KSIT BCS358B


Create a Data Frame in R
The syntax of the data.frame() function is
■ dataframe1 <- data.frame(
■ first_col = c(val1, val2, ...),
■ second_col = c(val1, val2, ...),
■ ...
■ )
■ Here,
■ first_col - a vector with values val1, val2, ... of same data type
■ second_col - another vector with values val1, val2, ... of same data type and so on

Prof. Namyapriya Dayananda, Asst Professor, CSE, KSIT BCS358B


Access Data Frame Columns
■ Here, we have used different
operators to access Name
column of dataframe1.
■ Accessing with [[ ]] or $ is
similar. However, it differs for
[ ], [ ] will return us a data
frame but the other two will
reduce it into a vector and
return a vector.

Prof. Namyapriya Dayananda, Asst Professor, CSE, KSIT BCS358B


Combine Data Frames
■ In R, we use the rbind() and the cbind() function to combine two data frames together.
■ rbind() - combines two data frames vertically
■ cbind() - combines two data frames horizontally
■ Combine Vertically Using rbind()
■ If we want to combine two data frames vertically, the column name of the two data
frames must be the same. For example,
■ Combine Horizontally Using cbind()
■ The cbind() function combines two or more data frames horizontally. For example,

Prof. Namyapriya Dayananda, Asst Professor, CSE, KSIT BCS358B


Length & Summary of a Data Frame in R
■ In R, we use the length() function to find the number of columns in a data frame. For
example,
■ In R, we use the summary() function to find the details in a data frame. For example,

Prof. Namyapriya Dayananda, Asst Professor, CSE, KSIT BCS358B

You might also like