Matching a range of dates to a single categorical variable Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?Create categorical variable in R based on rangeDataframes in a list; adding a new variable with name of dataframeCreating multiple time-series objects from a single data.frame with categoric variables as columns and dates as rowsadd column to data frame, testing categorical variable in other columnAvoid conflicts between vector and variable name in dplyrMerge one dataframe with a date vectorR: creating a categorical variable from a numerical variable and custom/open-ended/single-valued intervalsDetect a list of words in a string variable and extract matched words to a new variable in data framehow to split rows of a dataframe in multiple rows based on start date and end date?Find date elements in Dataframe Column that matches specific condition in R
When is phishing education going too far?
What are 'alternative tunings' of a guitar and why would you use them? Doesn't it make it more difficult to play?
Is the Standard Deduction better than Itemized when both are the same amount?
What happens to sewage if there is no river near by?
How does cp -a work
Right-skewed distribution with mean equals to mode?
Is high blood pressure ever a symptom attributable solely to dehydration?
Do I really need recursive chmod to restrict access to a folder?
Does the Giant Rocktopus have a Swim Speed?
What would be the ideal power source for a cybernetic eye?
Single word antonym of "flightless"
WAN encapsulation
IndentationError when pasting code in Python 3 interpreter mode
Does polymorph use a PC’s CR or its level?
Are my PIs rude or am I just being too sensitive?
How do I mention the quality of my school without bragging
Should I call the interviewer directly, if HR aren't responding?
How do I stop a creek from eroding my steep embankment?
Is it true to say that an hosting provider's DNS server is what links the entire hosting environment to ICANN?
How can players work together to take actions that are otherwise impossible?
How much radiation do nuclear physics experiments expose researchers to nowadays?
How to draw this diagram using TikZ package?
Letter Boxed validator
Is there a documented rationale why the House Ways and Means chairman can demand tax info?
Matching a range of dates to a single categorical variable
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?Create categorical variable in R based on rangeDataframes in a list; adding a new variable with name of dataframeCreating multiple time-series objects from a single data.frame with categoric variables as columns and dates as rowsadd column to data frame, testing categorical variable in other columnAvoid conflicts between vector and variable name in dplyrMerge one dataframe with a date vectorR: creating a categorical variable from a numerical variable and custom/open-ended/single-valued intervalsDetect a list of words in a string variable and extract matched words to a new variable in data framehow to split rows of a dataframe in multiple rows based on start date and end date?Find date elements in Dataframe Column that matches specific condition in R
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am a beginner using R, and I am wanting to create a dataframe that stores a range of dates to their respective classified time period.
paleo.periods <- c("Paleoindian","Early Paleoindian", "Middle Paleoindian", "Late Paleoindian", "Archaic","Early Archaic", "Middle Archaic","Late Archaic","Woodland","Early Woodland","Middle Woodland","Late Woodland","Late Prehistoric")
paleo.dates <- c(c(13500,8000), c(13500,10050) ,c(10050,9015), c(9015,8000), c(8000,2500), c(8000,5500), c(5500,3500), c(3500,2500), c(2500,1150), c(2500,2000), c(2000,1500), c(1500,1150), c(1150,500))
I would like for the arrangement to come out where I can refer to a given time period, ex: "Late Woodland", and get the associated vector of it's beginning and end timeframes, ex: (1500,1150)
I tried simply doing this by
paleo.seg <- data.frame(paleo.periods,paleo.dates)
however, this creates 3 variables: a list of the periods, a list of the vectors, and paleo.dates. I am not sure why it is creating 3 variables, as I'd like it to be only 2: paleo.periods and paleo.dates. I would also like to refer to them as paleo.seg$paleo.periods which will return the list of periods (and later use this to somehow refer to the periods individually), same with the dates.
Essentially I would like my dataframe to look a bit like this:
paleoperiods paleodates
"Late Woodland" 1500,1100
Therefore I could look specifically for the string "Late Woodland" and find the vector dates. I tried doing this on my current data.frame, and"Woodland" %in% paleo.seg returns false. So I feel like I am misunderstanding how to build a proper dataframe, as well as being able to match one categorical variable to two dates.
r dataframe
add a comment |
I am a beginner using R, and I am wanting to create a dataframe that stores a range of dates to their respective classified time period.
paleo.periods <- c("Paleoindian","Early Paleoindian", "Middle Paleoindian", "Late Paleoindian", "Archaic","Early Archaic", "Middle Archaic","Late Archaic","Woodland","Early Woodland","Middle Woodland","Late Woodland","Late Prehistoric")
paleo.dates <- c(c(13500,8000), c(13500,10050) ,c(10050,9015), c(9015,8000), c(8000,2500), c(8000,5500), c(5500,3500), c(3500,2500), c(2500,1150), c(2500,2000), c(2000,1500), c(1500,1150), c(1150,500))
I would like for the arrangement to come out where I can refer to a given time period, ex: "Late Woodland", and get the associated vector of it's beginning and end timeframes, ex: (1500,1150)
I tried simply doing this by
paleo.seg <- data.frame(paleo.periods,paleo.dates)
however, this creates 3 variables: a list of the periods, a list of the vectors, and paleo.dates. I am not sure why it is creating 3 variables, as I'd like it to be only 2: paleo.periods and paleo.dates. I would also like to refer to them as paleo.seg$paleo.periods which will return the list of periods (and later use this to somehow refer to the periods individually), same with the dates.
Essentially I would like my dataframe to look a bit like this:
paleoperiods paleodates
"Late Woodland" 1500,1100
Therefore I could look specifically for the string "Late Woodland" and find the vector dates. I tried doing this on my current data.frame, and"Woodland" %in% paleo.seg returns false. So I feel like I am misunderstanding how to build a proper dataframe, as well as being able to match one categorical variable to two dates.
r dataframe
2
Are you sure that's howpaleo.datesis formatted? The code you provided is just a vector of length 26. it doesn't contain "pairs" of numbers. And when I rundata.frameon it i get only two columns, not three variables. Was it supposed to be a list rather than a vector?
– MrFlick
Mar 8 at 16:13
Yes you are right, it didn't group them as I anticipated. Is there a quick fix for this?
– hkj447
Mar 8 at 16:15
add a comment |
I am a beginner using R, and I am wanting to create a dataframe that stores a range of dates to their respective classified time period.
paleo.periods <- c("Paleoindian","Early Paleoindian", "Middle Paleoindian", "Late Paleoindian", "Archaic","Early Archaic", "Middle Archaic","Late Archaic","Woodland","Early Woodland","Middle Woodland","Late Woodland","Late Prehistoric")
paleo.dates <- c(c(13500,8000), c(13500,10050) ,c(10050,9015), c(9015,8000), c(8000,2500), c(8000,5500), c(5500,3500), c(3500,2500), c(2500,1150), c(2500,2000), c(2000,1500), c(1500,1150), c(1150,500))
I would like for the arrangement to come out where I can refer to a given time period, ex: "Late Woodland", and get the associated vector of it's beginning and end timeframes, ex: (1500,1150)
I tried simply doing this by
paleo.seg <- data.frame(paleo.periods,paleo.dates)
however, this creates 3 variables: a list of the periods, a list of the vectors, and paleo.dates. I am not sure why it is creating 3 variables, as I'd like it to be only 2: paleo.periods and paleo.dates. I would also like to refer to them as paleo.seg$paleo.periods which will return the list of periods (and later use this to somehow refer to the periods individually), same with the dates.
Essentially I would like my dataframe to look a bit like this:
paleoperiods paleodates
"Late Woodland" 1500,1100
Therefore I could look specifically for the string "Late Woodland" and find the vector dates. I tried doing this on my current data.frame, and"Woodland" %in% paleo.seg returns false. So I feel like I am misunderstanding how to build a proper dataframe, as well as being able to match one categorical variable to two dates.
r dataframe
I am a beginner using R, and I am wanting to create a dataframe that stores a range of dates to their respective classified time period.
paleo.periods <- c("Paleoindian","Early Paleoindian", "Middle Paleoindian", "Late Paleoindian", "Archaic","Early Archaic", "Middle Archaic","Late Archaic","Woodland","Early Woodland","Middle Woodland","Late Woodland","Late Prehistoric")
paleo.dates <- c(c(13500,8000), c(13500,10050) ,c(10050,9015), c(9015,8000), c(8000,2500), c(8000,5500), c(5500,3500), c(3500,2500), c(2500,1150), c(2500,2000), c(2000,1500), c(1500,1150), c(1150,500))
I would like for the arrangement to come out where I can refer to a given time period, ex: "Late Woodland", and get the associated vector of it's beginning and end timeframes, ex: (1500,1150)
I tried simply doing this by
paleo.seg <- data.frame(paleo.periods,paleo.dates)
however, this creates 3 variables: a list of the periods, a list of the vectors, and paleo.dates. I am not sure why it is creating 3 variables, as I'd like it to be only 2: paleo.periods and paleo.dates. I would also like to refer to them as paleo.seg$paleo.periods which will return the list of periods (and later use this to somehow refer to the periods individually), same with the dates.
Essentially I would like my dataframe to look a bit like this:
paleoperiods paleodates
"Late Woodland" 1500,1100
Therefore I could look specifically for the string "Late Woodland" and find the vector dates. I tried doing this on my current data.frame, and"Woodland" %in% paleo.seg returns false. So I feel like I am misunderstanding how to build a proper dataframe, as well as being able to match one categorical variable to two dates.
r dataframe
r dataframe
edited Mar 8 at 16:11
MrFlick
125k12142175
125k12142175
asked Mar 8 at 16:08
hkj447hkj447
405
405
2
Are you sure that's howpaleo.datesis formatted? The code you provided is just a vector of length 26. it doesn't contain "pairs" of numbers. And when I rundata.frameon it i get only two columns, not three variables. Was it supposed to be a list rather than a vector?
– MrFlick
Mar 8 at 16:13
Yes you are right, it didn't group them as I anticipated. Is there a quick fix for this?
– hkj447
Mar 8 at 16:15
add a comment |
2
Are you sure that's howpaleo.datesis formatted? The code you provided is just a vector of length 26. it doesn't contain "pairs" of numbers. And when I rundata.frameon it i get only two columns, not three variables. Was it supposed to be a list rather than a vector?
– MrFlick
Mar 8 at 16:13
Yes you are right, it didn't group them as I anticipated. Is there a quick fix for this?
– hkj447
Mar 8 at 16:15
2
2
Are you sure that's how
paleo.dates is formatted? The code you provided is just a vector of length 26. it doesn't contain "pairs" of numbers. And when I run data.frame on it i get only two columns, not three variables. Was it supposed to be a list rather than a vector?– MrFlick
Mar 8 at 16:13
Are you sure that's how
paleo.dates is formatted? The code you provided is just a vector of length 26. it doesn't contain "pairs" of numbers. And when I run data.frame on it i get only two columns, not three variables. Was it supposed to be a list rather than a vector?– MrFlick
Mar 8 at 16:13
Yes you are right, it didn't group them as I anticipated. Is there a quick fix for this?
– hkj447
Mar 8 at 16:15
Yes you are right, it didn't group them as I anticipated. Is there a quick fix for this?
– hkj447
Mar 8 at 16:15
add a comment |
1 Answer
1
active
oldest
votes
There are a few ways that you could go about this depending on your reasoning about what you want to do with your dataframe. My recommendation would actually be to split the dates column into two separate date columns(start and end I believe, from your description). This way you could calculate or use rules based on the dates. I've found this useful when looking at data, as it gives you the ability to filter based on two different aspects of the date. If you would like them to be in the same column, you could make the dates a character in order to have them in the same column. However, this approach does have drawbacks in terms of using it for exploratory data analysis. An example of this would be:
paleo.dates <- c("13500,8000","13500,10050","10050,9015","9015,8000", ...)
This would allow you to look up Late Woodland and get "1500,1100", but you wouldn't be able to search for periods occurring after 1500 if that type of analysis is something you would be doing at a later point.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55066926%2fmatching-a-range-of-dates-to-a-single-categorical-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are a few ways that you could go about this depending on your reasoning about what you want to do with your dataframe. My recommendation would actually be to split the dates column into two separate date columns(start and end I believe, from your description). This way you could calculate or use rules based on the dates. I've found this useful when looking at data, as it gives you the ability to filter based on two different aspects of the date. If you would like them to be in the same column, you could make the dates a character in order to have them in the same column. However, this approach does have drawbacks in terms of using it for exploratory data analysis. An example of this would be:
paleo.dates <- c("13500,8000","13500,10050","10050,9015","9015,8000", ...)
This would allow you to look up Late Woodland and get "1500,1100", but you wouldn't be able to search for periods occurring after 1500 if that type of analysis is something you would be doing at a later point.
add a comment |
There are a few ways that you could go about this depending on your reasoning about what you want to do with your dataframe. My recommendation would actually be to split the dates column into two separate date columns(start and end I believe, from your description). This way you could calculate or use rules based on the dates. I've found this useful when looking at data, as it gives you the ability to filter based on two different aspects of the date. If you would like them to be in the same column, you could make the dates a character in order to have them in the same column. However, this approach does have drawbacks in terms of using it for exploratory data analysis. An example of this would be:
paleo.dates <- c("13500,8000","13500,10050","10050,9015","9015,8000", ...)
This would allow you to look up Late Woodland and get "1500,1100", but you wouldn't be able to search for periods occurring after 1500 if that type of analysis is something you would be doing at a later point.
add a comment |
There are a few ways that you could go about this depending on your reasoning about what you want to do with your dataframe. My recommendation would actually be to split the dates column into two separate date columns(start and end I believe, from your description). This way you could calculate or use rules based on the dates. I've found this useful when looking at data, as it gives you the ability to filter based on two different aspects of the date. If you would like them to be in the same column, you could make the dates a character in order to have them in the same column. However, this approach does have drawbacks in terms of using it for exploratory data analysis. An example of this would be:
paleo.dates <- c("13500,8000","13500,10050","10050,9015","9015,8000", ...)
This would allow you to look up Late Woodland and get "1500,1100", but you wouldn't be able to search for periods occurring after 1500 if that type of analysis is something you would be doing at a later point.
There are a few ways that you could go about this depending on your reasoning about what you want to do with your dataframe. My recommendation would actually be to split the dates column into two separate date columns(start and end I believe, from your description). This way you could calculate or use rules based on the dates. I've found this useful when looking at data, as it gives you the ability to filter based on two different aspects of the date. If you would like them to be in the same column, you could make the dates a character in order to have them in the same column. However, this approach does have drawbacks in terms of using it for exploratory data analysis. An example of this would be:
paleo.dates <- c("13500,8000","13500,10050","10050,9015","9015,8000", ...)
This would allow you to look up Late Woodland and get "1500,1100", but you wouldn't be able to search for periods occurring after 1500 if that type of analysis is something you would be doing at a later point.
answered Mar 8 at 16:25
kirschilkirschil
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55066926%2fmatching-a-range-of-dates-to-a-single-categorical-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Are you sure that's how
paleo.datesis formatted? The code you provided is just a vector of length 26. it doesn't contain "pairs" of numbers. And when I rundata.frameon it i get only two columns, not three variables. Was it supposed to be a list rather than a vector?– MrFlick
Mar 8 at 16:13
Yes you are right, it didn't group them as I anticipated. Is there a quick fix for this?
– hkj447
Mar 8 at 16:15