What are the very basics of R and where can I find information on commonly asked questions about R?

What are the very basics of R and where can I find information on commonly asked questions about R?

R is a programming language and environment for statistical computing and graphics. It is widely used in data analysis, statistical modeling, and machine learning. The basics of R include data types, data structures, and functions that allow users to manipulate and analyze data. R also has a vast library of packages that provide additional functionalities for specific tasks.

Information on commonly asked questions about R can be found on various online resources such as official documentation, tutorials, forums, and blogs. The official website for R, https://www.r-project.org/, provides comprehensive documentation and resources for beginners and experienced users. Additionally, there are many online communities and forums, such as Stack Overflow and RStudio Community, where users can ask and find answers to their questions. There are also many books and online courses available for those who want to learn R in a more structured manner.

The very basics of R | R FAQ

This page is designed to be a cheat sheet answering the most
basic and fundamental questions that commonly come up when using R. Note that
it is by no means intended to be an exhaustive list of the commonly used R functions.

Q:  What is a package?

A package is a collection or group of objects that R can use.  A package may contain 
functions, data frames, or other objects, such as dynamically loaded libraries of 
compiled code.

Q:  How do I see which packages I have available?

library()

Q: How do I load a package?

library("package_name")

Q: How do I see the documentation for a particular package?

library(help="package_name")
help(package="package_name")

Q: How do I see the help file for a specific function?

help("function_name")
?function_name

Q: How can I save my work?

You can save all the objects and functions that you have created in an .RData file, 
by using the save or the save.image functions.  It is very important that you 
remember to include the .RData extension when indicating the file path because R will not 
supply it for you!

save(file="c:/temp/file_name.RData")
save.image("c:/temp/file_name.RData")

On a PC you can also access this through the file menu:
File
  Save workspace
  browse to the folder where you want to save the file and 
  supply the file name of your choice

Q: How can I retrieve the work that I have saved using a save.image function?

The load function will load an .RData file.
load("c:/temp/file_name.RData")

On a PC you can also access this through the file menu:
File
  Load workspace
  browse to the folder where you saved the .RData file and click open

Q: How do I save all the commands that I have used in an R session?

You can save a history of your R session in an .Rhistory file by using 
the history function.  It is very important that you remember to include the .Rhistory 
extension when indicating the file path because R will not supply it for you!

history("c:/temp/file_name.Rhistory")

On a PC you can also access this through the file menu:
File
  Save history
  browse to the folder where you want to save the file and 
  supply the file name of your choice

Q: How can I retrieve the work that I have saved using a history function?

The loadhistory function will load an .Rhistory file.
loadhistory("c:/temp/file_name.Rhistory")

On a PC you can also access this through the file menu:
File
  Load history
  browse to the folder where you saved the .Rhistory file and click open

Q: How do I use a script of commands and functions saved in a
text file?

source("c:/temp/file_name.txt")

Q: How do I get R to echo back the commands and functions in a script
that I am sourcing into R? For example, if I have written functions and I want
to see the functions being executed.

source("c:/temp/file_name.txt", echo=T)

Q: How do I close the help file when working on a Macintosh?

Typing q will close the help file and bring you back to the console.

Q: How can I see a list of the objects that are currently available?

objects()
ls()

Q: How do I remove unwanted objects and functions?

rm(object_name1, object_names2, etc.)
rm(function_name1, function_name2, etc.)

Q: What is the first thing to check if a function or object is behaving strangely
and unexpectedly?

Always check if there is a masked object or function which is being used instead of the 
object or function that you intended to use.  If this is the case then the object or function 
can be removed by using the rm function as shown in the previous answer.
masked()

Cite this article

stats writer (2024). What are the very basics of R and where can I find information on commonly asked questions about R?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/what-are-the-very-basics-of-r-and-where-can-i-find-information-on-commonly-asked-questions-about-r/

stats writer. "What are the very basics of R and where can I find information on commonly asked questions about R?." PSYCHOLOGICAL SCALES, 30 Jun. 2024, https://scales.arabpsychology.com/stats/what-are-the-very-basics-of-r-and-where-can-i-find-information-on-commonly-asked-questions-about-r/.

stats writer. "What are the very basics of R and where can I find information on commonly asked questions about R?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/what-are-the-very-basics-of-r-and-where-can-i-find-information-on-commonly-asked-questions-about-r/.

stats writer (2024) 'What are the very basics of R and where can I find information on commonly asked questions about R?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/what-are-the-very-basics-of-r-and-where-can-i-find-information-on-commonly-asked-questions-about-r/.

[1] stats writer, "What are the very basics of R and where can I find information on commonly asked questions about R?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. What are the very basics of R and where can I find information on commonly asked questions about R?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top