How to add a new column in the existing Data frame using R language
In this question we will add a new column to an existing data frame
In this question we will add a new column to an existing data frame
In this question we will add a new column to an existing data frame
Student <- data.frame( RollNo = 1:10, Marks = c(10, 20, 30, 40, 50, 60, 70, 80, 90, 100), PassOrFail = c(F, F, F, F, F, T, T, T, T, T))
In this Data Frame we will add a column StudentName
> StudentName <- c("Rumman", "Inza", "Jaman", "Azam", "Samser","Kamran","Roman", "Ali", "Ansar", "Sfik")
> Student$StudentName <- StudentName
<img src="/library/images-tutorials/add-new-column-to-dataframe.png" alt="data frame, r language" class="img-responsive">
> str(Student)
'data.frame': 10 obs. of 4 variables:
$ RollNo : int 1 2 3 4 5 6 7 8 9 10
$ Marks : num 10 20 30 40 50 60 70 80 90 95
$ PassOrFail : logi FALSE FALSE FALSE FALSE FALSE TRUE ...
$ StudentName: chr "Rumman" "Inza" "Jaman" "Azam" ...
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.