r4ds | R for data science : a book
kandi X-RAY | r4ds Summary
kandi X-RAY | r4ds Summary
R for data science: a book
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of r4ds
r4ds Key Features
r4ds Examples and Code Snippets
Community Discussions
Trending Discussions on r4ds
QUESTION
i'm having the following problem:
Context:
I'm using gtsummary
to explore frequencies in a dataframe using cross variables.
So that i have a main variable tobgp
and its cross by multiple variables like agegp
and algp
Attempt:
this is what i've done so far. Using the esoph
data from the package The R Datasets Package (datasets).
ANSWER
Answered 2022-Mar-28 at 15:29you are pretty close and only needed a few modifications. the major change is adding in an lapply()
to loop through the vars
input to create a list of tbl_summary
objects. Then I create the tab spanner names from the inputs of vars
and append the t0
table to the list created by the lapply()
. then you can pass tlist2
to tbl_merge()
with the names created with tabspannername
to dynamically label the tables.
QUESTION
I have 3 r scripts;
- data1.r
- data2.r
- graph1.r
the two data files, run some math and generate 2 separate data files, which I save in my working directory. I then call these two files in graph1.r and use it to plot the data.
How can I organise and create an R project which has;
- these two data files - data1.r and data2.r
- another file which calls these files (graph1.r)
- Output of graph1.r
I would then like to share all of this on GitHub (I know how to do this part).
Edit -
Here is the data1 script
...ANSWER
Answered 2022-Mar-20 at 07:25I have broken my answer into three parts:
- The question in your title
- The reworded question in your text
- What I, based on your comments, believe you are actually asking
From RStudio, just create a new project and move your files to this folder. You can then initialize this folder with git using git init
.
You don't need to change anything in your example code. If you just place your files in a project folder they will run just fine.
An R project mainly takes care of the following for you:
- Working directory (it's always set to the project folder)
- File paths (all paths are relative to the project root folder)
- Settings (you can set project specific settings)
Further, many external packages are meant to work with projects, making many task easier for you. A project is also a very good starting point for sharing your code with Git.
What would be a good workflow for working with multiple scripts in an R project?One common way of organizing multiple scripts is to make a new script calling the other scripts in order. Typically, I number the scripts so it's easy to see the order to call them. For example, here I would create 00_main.R
and include the code:
QUESTION
I've been trying follow the approach set out by Hadley Wickham for running multiple models in a nested data frame as per https://r4ds.had.co.nz/many-models.html
I've managed to write this code below to create the multiple linear models:
...ANSWER
Answered 2022-Feb-09 at 10:25You have to specify the relevant arguments inside map
. There are two possibilities:
QUESTION
groups <- data.frame(group = c("A", "B"),
Reels = c(155, 343),
Fish = c(41, 221))
groups %>%
ggplot(aes(x = group, y = Reels)) +
geom_col() +
labs(
x = "Group",
y = "Count"
)
...ANSWER
Answered 2021-Dec-30 at 21:35Try this, with a text label thrown in for good measure:
QUESTION
So, I have this simple script which converts videos in a folder into a format which the R4DS can play.
...ANSWER
Answered 2021-Nov-14 at 11:33You cannot use -name
because the search is on the path now. My first solution was:
QUESTION
Earlier, I asked how to create [global environment objects from a tibble 1, which I have been able to do.
Now, I want to take the objects generated from the tibble to use in a function similar to this:
...ANSWER
Answered 2021-Oct-08 at 20:59We may get those objects from the global env with mget
, stack
it to a two column data.frame
QUESTION
I'm very new to regular expressions, so my apologies if this is an obviously stupid question.
Suppose I have a string of the form (c"fair*", "beaut*") and I want to replace the asterisk (*) at the end by a caret (^) at the beginning: c("^fair", "^beaut"). How could I go about doing that using stringr? I have read this excellent introduction to regexp, but did not figure it out. I made several attempts with stringr::str_replace_all(), to no avail. The issue seems to be that the replacement in stringr::str_replace_all() can't be a regexp. Is that so? If yes, is there any other way to do this?
...ANSWER
Answered 2021-Sep-15 at 21:37You can use
QUESTION
When I try to render the latest version of the book R for Data Science (R4DS), I get as far as LaTeX compilation, then am stopped by the following error message.
...ANSWER
Answered 2021-Jun-24 at 01:15It looks like I "solved" the problem by changing an option in the _common.R
file from crayon.enabled=TRUE
to crayon.enabled=FALSE
. This removed the ANSI escape sequences from the book. Previously I had tried setting options(crayon.enabled=FALSE)
in my R session, but this was evidently being overridden by the setting in _common.R
.
QUESTION
The R4DS book has the following code block:
...ANSWER
Answered 2021-Jun-10 at 18:08We could use proportions
on the table
output after subset
ting to remove the NA
(complete.cases
) and select
ing the columns
The data is from forcats
package. So, load the package and get the data
QUESTION
I was recently reading a solution to an R4DS exercise. It includes the code:
...ANSWER
Answered 2021-Jun-04 at 19:52with the letters/LETTERS
, use
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install r4ds
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page