CSV to R Converter




CSV Preview

R Code Output


                
            
Advertisement




CSV to R Programming

R is a powerful language for statistical computing and data analysis. In this article, we will learn how to read a CSV file containing country data into R.

Installing Required Package

R has a built-in function for reading CSV files, but you can also use the readr package for better performance. To install it, use the following command:

install.packages("readr")

Loading a CSV File

To load a CSV file into an R data frame, use the read_csv function from the readr package:

library(readr)

data <- read_csv("countries.csv")
print(head(data))
    

Sample CSV File

Here is an example of what a countries.csv file might look like:

Country,Capital,Population
India,New Delhi,1393409038
USA,Washington D.C.,331449281
UK,London,67886011
Canada,Ottawa,37742154
Australia,Canberra,25499884
    

Working with the Data

Once loaded into a data frame, you can perform various operations such as filtering, sorting, and summarizing. For example, to display countries with a population greater than 100 million:

filtered_data <- subset(data, Population > 100000000)
print(filtered_data)
    

Conclusion

Using R, you can easily load, manipulate, and analyze country data from a CSV file. This is useful for data analysis, visualization, and other applications.