DEV Community

stuxnat
stuxnat

Posted on

3 2

Using R Libraries and Working with Data

Packages in R can contain code, data, and documentation. These are stored in libraries, and provide functionality features to R, like reading .csv files. Packages can be installed with the install.packages() command.
Example:

install.packages("readxl")

Whenever you use a library that is not native to R, it must be loaded into R by using the library() function.

library("readxl")

Excel files can be read with the read_excel() function.

read_excel("/filepath/file.xls)

Similarly, data from a .csv file can be stored and accessed like this:

data <- read.csv("/filepath/datafile.csv")

data

That should show you the rows and columns from the .csv file, which you can then perform operations and analysis on.

More useful functions for working with data files:

readLines() - read text file into character vector
write() - export a dataset as text file
write.csv() & write.table() - export a dataset as .csv file
write.xlsx() - export a dataset as Excel file
save() - save R objects in .RData files

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay