[R] Subtracting Data Frame With a Different Number of Rows

2020-04-21 Thread Phillip Heinrich
I have two small data frames of baseball data. The first one is the mean number of runs that will score in each half inning for the 2018 Arizona Diamondbacks. The second data frame is the same information but for only one player. As you will see the individual player did not come up to bat a

[R] Tidyverse Question

2020-03-23 Thread Phillip Heinrich
Can someone out there run the following code from the book Analyzing Baseball Data with R – Chapter 7 page 164? library(tidyverse) db <- src_sqlite(“data/pitchrx.sqlite”,create=TRUE) Over the past two weeks this code has run correctly twice but I have gotten the following error dozens o

[R] Analyzing Baseball Data With R

2020-03-16 Thread Phillip Heinrich
Can’t get past first step of Chapter 7 page 164. Opened a new RStudio window. Loaded tidyverse and keyed in library(tidyverse) which of course includes dplyr. The working directory is: C:/Users/Owner/Documents. Then keyed in: db <- src_sqlite(“data/pitchrx.sqlite”,create=TRUE) And got the fo

[R] Accessing Data From packages

2020-02-27 Thread Phillip Heinrich
I am continuing to have problems downloading data as prescribed in books about R such as “Analyzing Baseball Data with R”. In chapter 3 (page 67) the instructions to download baseball Hall of Fame data from the package tidyverse are: library(tidyverse) -- Attaching packages --

[R] Data Carpentry - Creating a New SQLite Database

2020-01-10 Thread Phillip Heinrich
Working my way through a tutorial named Data Carpentry (https://datacarpentry.org/R-ecology-lesson/). for the most part it is excellent but I’m stuck on the very last section (https://datacarpentry.org/R-ecology-lesson/05-r-and-databases.html). First, below are the packages I have loaded: [1]

[R] If Loop I Think

2019-10-22 Thread Phillip Heinrich
Row Outs RunnerFirst RunnerSecond RunnerThird R1 R2 R3 1 0 2 1 3 1 4 1 arenn001 5 2 arenn001 6 0 7 0 perad001 8 0 polla001 perad001 9 0 goldp001 polla001 perad001 10 0 lambj001

[R] Another Real Basic Question

2019-10-16 Thread Phillip Heinrich
In the Source window of RStudio (upper left) I save my code (File/Save) but can not reload it. There is a file labeled (RECode.R) but neither File/Open file or File/Recent Files gets me anywhere. Any ideas what I’m doing wrong. [[alternative HTML version deleted]] _

[R] mapple

2019-10-01 Thread Phillip Heinrich
With the snippet of data below I’m trying to do an if/then type of thing: row 1 – if all five variables equal 0 then code equals 1; row 3 – if v1 = 1 and v2 = 1 then code = 5; row 7 – if v1 = 0 and v2 = 1 and v3 = 2 then code = 10 There are 24 codes in the complete database. v1 v2

[R] Real Basic Question

2019-09-26 Thread Phillip Heinrich
Just when I think I’m starting to get the hang of R I run into something that sends me back to Go without collecting $200. The working directory seems to be correct when I load an .rda file but it is not there and it is not in the Global Environment in the upper right hand window in RStudio. ge

[R] Creating a Date Field

2019-09-24 Thread Phillip Heinrich
The date is imbedded in the GameID character field so I created a date vector with the following code: ari18.test3$date <- substring(ari18.test3$GameID,4,11) And then created a new dataframe with just the Game ID and date vectors. The date field is a character as shown by the str() command. s

[R] & statement within an ifelse Loop

2019-09-21 Thread Phillip Heinrich
Still putzing around trying to increment a count vector when the date changes. Date count 1 2018-03-29 1 2 2018-03-29 1 3 2018-03-29 1 81 2018-03-30 1 82 2018-03-30 1 83 2018-03-30 1 165 2018-03-31 1 166 2018-03-31 1 167 2018-03-31 1 I can

[R] Loop With Dates

2019-09-20 Thread Phillip Heinrich
With the data snippet below I’m trying to increment the “count” vector by one each time the date changes. Date count 1 2018-03-29 1 2 2018-03-29 1 3 2018-03-29 1 81 2018-03-30 1 82 2018-03-30 1 83 2018-03-30 1 165 2018-03-31 1 166 2018-03-31 1 1

[R] If Loop With Lagged Variable

2019-09-19 Thread Phillip Heinrich
Attached is every at bat for the Arizona Diamondback’s first three games of 2018 – BBdata1.rda. I added the Date and DHCode variables by parsing the first variable labeled GameID. BBdata2 is a reduced dataset with five variables as shown in the str() command. data.frame':234 obs. of 5 var