Tag: r

52 votes
16 answers
3K views
Changing column names of a data frame

I have a data frame called "newprice" (see below) and I want to change the column names in my program in R. &

avatar
Luis
0 1 0 9
asked 07 September, 2021
62 votes
9 answers
1.7K views
Check existence of directory and create if doesn't exist

I often find myself writing R scripts that generate a lot of output. I find it cleaner to put this output into

r
avatar
Nereida
0 1 0 9
asked 07 September, 2021
57 votes
30 answers
2.1K views
How to find the statistical mode?

In R, mean() and median() are standard functions which do what you'd expect. mode() tells you the intern

avatar
Corrin
0 1 0 9
asked 07 September, 2021
57 votes
20 answers
1.6K views
Counting the number of elements with the values of x in a vector

I have a vector of numbers: numbers <- c(4,23,4,23,5,43,54,56,657,67,67,435, 453,435,324,34,456,5

avatar
Rudy
0 1 0 9
asked 07 September, 2021
57 votes
8 answers
526 views
Cluster analysis in R: determine the optimal number of clusters

Being a newbie in R, I'm not very sure how to choose the best number of clusters to do a k-means analysis

avatar
Sachiko
0 1 0 9
asked 07 September, 2021
61 votes
13 answers
908 views
How to find out which package version is loaded in R?

I am in a process of figuring out how to use my university cluster. It has 2 versions of R installed. System w

avatar
Tuan
0 1 0 9
asked 07 September, 2021
56 votes
28 answers
691 views
Tricks to manage the available memory in an R session

What tricks do people use to manage the available memory of an interactive R session? I use the functions bel

avatar
Solomon
0 1 0 9
asked 07 September, 2021
58 votes
11 answers
2.7K views
Quickly reading very large tables as dataframes

I have very large tables (30 million rows) that I would like to load as a dataframes in R. read.table() has a

avatar
Thurman
0 1 0 9
asked 07 September, 2021
58 votes
17 answers
2.1K views
Create an empty data.frame

I'm trying to initialize a data.frame without any rows. Basically, I want to specify the data types for e

avatar
Keila
0 1 0 9
asked 07 September, 2021
63 votes
7 answers
2.7K views
Run R script from command line

I have a file, called a.r, it has a chmod of 755, sayHello <- function(){ print('hello') } s

avatar
Keith
0 1 0 9
asked 07 September, 2021
59 votes
7 answers
2.1K views
Test if a vector contains a given element

How to check if a vector contains a given value?

avatar
Jesenia
0 1 0 9
asked 07 September, 2021
46 votes
15 answers
710 views
Drop unused factor levels in a subsetted data frame

I have a data frame containing a factor. When I create a subset of this dataframe using subset or another inde

avatar
Omar
0 1 0 9
asked 07 September, 2021
67 votes
24 answers
2.5K views
Convert a list to a data frame

I have a nested list of data. Its length is 132 and each item is a list of length 20. Is there a quick way to

avatar
Shanita
0 1 0 9
asked 07 September, 2021
49 votes
12 answers
2.6K views
The difference between bracket [ ] and double bracket [[ ]] for accessing the elements of a list or dataframe

R provides two different methods for accessing the elements of a list or data.frame: [] and [[]]. What is the

avatar
Xavier
0 1 0 9
asked 07 September, 2021
57 votes
12 answers
2.6K views
How to unload a package without restarting R

I'd like to unload a package without having to restart R (mostly because restarting R as I try out differ

avatar
Vi
0 1 0 9
asked 07 September, 2021
57 votes
8 answers
2.2K views
What is the difference between require() and library()?

What is the difference between require() and library()?

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
53 votes
18 answers
825 views
How should I deal with "package &apos;xxx&apos; is not available (for R version x.y.z)" warning?

I tried to install a package, using install.packages("foobarbaz") but received the warning Warning message

avatar
Percy
0 1 0 9
asked 07 September, 2021
44 votes
11 answers
1K views
How can I view the source code for a function?

I want to look at the source code for a function to see how it works. I know I can print a function by typing

avatar
Elicia
0 1 0 9
asked 07 September, 2021
57 votes
16 answers
2.3K views
Plot two graphs in same plot in R

I would like to plot y1 and y2 in the same plot. x <- seq(-2, 2, 0.05) y1 <- pnorm(x) y2 <- pnorm(x

avatar
Lynette
0 1 0 9
asked 07 September, 2021
61 votes
11 answers
1.1K views
How to convert a factor to integer umeric without loss of information?

When I convert a factor to a numeric or integer, I get the underlying level codes, not the values as numbers.

avatar
Royal
0 1 0 9
asked 07 September, 2021