Displaying 20 results from an estimated 8000 matches similar to: "Convert character date time to R date-time variable."
2024 Nov 27
7
R Processing dataframe by group - equivalent to SAS by group processing with a first. and retain statments
I am an old, long time SAS programmer. I need to produce R code that processes a dataframe in a manner that is equivalent to that produced by using a by statement in SAS and an if first.day statement and a retain statement:
I want to take data (olddata) that looks like this
ID Day
1 1
1 1
1 2
1 2
1 3
1 3
1 4
1 4
1 5
1 5
2 5
2 5
2 5
2 6
2 6
2 6
3 10
3 10
and make it look like this:
(withing each
2024 Nov 27
3
Convert string to date time
I am reading a string that has the following form:
"2020-08-26_05:15:01"
I want to convert the string to a date-time variable. I tired:
x <- "2007-02-01_10:10:30"
x <- as.POSIXct(x,tz=Sys.timezone())
x
but this did not work; the time portion was ignored. I suspect the problem is the _ between the date and time, but I don't know how to account for this character in
2023 Dec 07
1
Convert character date time to R date-time variable.
?s 16:21 de 07/12/2023, Sorkin, John escreveu:
> Colleagues,
>
> I have a matrix of character data that represents date and time. The format of each element of the matrix is
> "2020-09-17_00:00:00"
> How can I convert the elements into a valid R date-time constant?
>
> Thank you,
> John
>
>
>
> John David Sorkin M.D., Ph.D.
> Professor of
2024 Nov 29
3
Trying to get the prior value of a record from a data.frame . . . data.frame
I need to write code that will give me the previous value of from a data.frame. I have written the following code using the shift function from data.table . It does not work. I hope someone can help me correct the code.
###########################
# Try to understand shift #
###########################
if(!require(data.table)) install.packages("data.table")
library(data.table)
# Create
2024 Jun 08
3
Can't compute row means of two columns of a dataframe.
I have a data frame with three columns, TotalInches, Low20, High20. For each row of the dataset, I am trying to compute the mean of Low20 and High20.
xxxz <- structure(list(TotalInches =
c(58, 59, 60, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76), Low20 = c(84, 87,
90, 93, 96, 99, 102, 106, 109, 112, 116, 119, 122,
2024 May 09
2
Print date on y axis with month, day, and year
I am trying to use ggplot to plot the data, and R code, below. The dates (jdate) are printing as Mar 01, Mar 15, etc. I want to have the date printed as MMM DD YYYY (or any other way that will show month, date, and year, e.g. mm/dd/yy). How can I accomplish this?
yyy <- structure(list(
jdate = structure(c(19052, 19053, 19054, 19055,
19058, 19059, 19060, 19061, 19062,
2024 Dec 01
6
Identify first row of each ID within a data frame, create a variable first =1 for the first row and first=0 of all other rows
Dear R help folks,
First my apologizes for sending several related questions to the list server. I am trying to learn how to manipulate data in R . . . and am having difficulty getting my program to work. I greatly appreciate the help and support list member give!
I am trying to write a program that will run through a data frame organized by ID and for the first line of each new group of data
2023 Dec 07
1
Convert character date time to R date-time variable.
Look at the lubridate package in R.
Regards,
Tim
-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Sorkin, John
Sent: Thursday, December 7, 2023 11:22 AM
To: r-help at r-project.org (r-help at r-project.org) <r-help at r-project.org>
Subject: [R] Convert character date time to R date-time variable.
[External Email]
Colleagues,
I have a matrix of
2024 Nov 27
4
R Processing dataframe by group - equivalent to SAS by group processing with a first. and retain statments
Check out the dplyr package, specifically the mutate function.
# Create new column based on existing column value
df <- df %>% mutate(FirstDay = if(ID = 2, 5))
df
Repeat as needed to capture all of the day/firstday combinations you want to account for.
Like everything else in R, there are probably at least a dozen other ways to do this, between base R and all of the library packages
2023 Dec 08
1
Convert character date time to R date-time variable.
On 12/7/23 08:21, Sorkin, John wrote:
> Colleagues,
>
> I have a matrix of character data that represents date and time. The format of each element of the matrix is
> "2020-09-17_00:00:00"
> How can I convert the elements into a valid R date-time constant?
You will not be able to store these datetime values in an R matrix, at
least as class POSIXct. You could with class
2024 Dec 01
2
Identify first row of each ID within a data frame, create a variable first =1 for the first row and first=0 of all other rows
Rui:
"f these two, diff is faster. But of all the solutions posted so far,
Ben Bolker's is the fastest."
But the explicit version of diff is still considerably faster:
> D <- c(rep(1,10),rep(2,6),rep(3,2))
> microbenchmark(c(1L,diff(D)), times = 1000L)
Unit: microseconds
expr min lq mean median uq max neval
c(1L, diff(D)) 3.075 3.198 3.34396
2024 Jan 04
1
Obtaining a value of pie in a zero inflated model (fm-zinb2)
I am running a zero inflated regression using the zeroinfl function similar to the model below:
fm_zinb2 <- zeroinfl(art ~ . | ., data = bioChemists, dist = "poisson")
summary(fm_zinb2)
I have three questions:
1) How can I obtain a value for the parameter pie, which is the fraction of the population that is in the zero inflated model vs the fraction in the count model?
2) For
2023 Dec 08
1
Convert two-dimensional array into a three-dimensional array.
Colleagues
I want to convert a 10x2 array:
# create a 10x2 matrix.
datavals <- matrix(nrow=10,ncol=2)
datavals[,] <- rep(c(1,2),10)+c(rnorm(10),rnorm(10))
datavals
into a 10x3 array, ThreeDArray, dim(10,2,10).
The values storede in ThreeDArray's first dimensions will be the data stored in datavalues.
ThreeDArray[i,,] <- datavals[i,]
The values storede in ThreeDArray's second
2024 Jun 08
1
Can't compute row means of two columns of a dataframe.
Use apply(), not by().
xxxz$av20 <- apply(xxxz[,c("Low20","High20")],1, mean)
-- Bert
On Sat, Jun 8, 2024 at 10:38?AM Sorkin, John <jsorkin at som.umaryland.edu>
wrote:
> I have a data frame with three columns, TotalInches, Low20, High20. For
> each row of the dataset, I am trying to compute the mean of Low20 and
> High20.
>
> xxxz <-
2024 Dec 06
1
ggplot2: Plot multiple lines using stacked data.
I am trying to use ggplot2 to create a figure with multiple lines, one line for each value of the variable Day. Each group of data for Day requires seven lines. The dataframe has data for 4 days and thus 4*7=28 lines.
I can create a plot, but the plot only contains dots. The dots for each day should be connected each day's data by a different line. There should be a total of four lines on the
2024 Dec 11
2
SQL and R
Dear Askay,
I believe my grey hair allows me to help answer your question. SQL, and its progenitor SEQUEL, were developed specifically to manipulate relational databases. It was developed in the early 1970s (equivalent to the historical bronze age) when the concept of a relational database (see https://en.wikipedia.org/wiki/Relational_database) and Codd's 12-rules were being developed (see
2024 Dec 11
2
aggregate produces results in unexpected format
I am trying to use the aggregate function to run a function, catsbydat2, that produces the mean, minimum, maximum, and number of observations of the values in a dataframe, inJan2Test, by levels of the dataframe variable MyDay. The output should be in the form of a dataframe.
#my code:
# This function should process a data frame and return a data frame
# containing the mean, minimum, maximum, and
2024 Nov 27
1
R Processing dataframe by group - equivalent to SAS by group processing with a first. and retain statments
?s 16:30 de 27/11/2024, Sorkin, John escreveu:
> I am an old, long time SAS programmer. I need to produce R code that processes a dataframe in a manner that is equivalent to that produced by using a by statement in SAS and an if first.day statement and a retain statement:
>
> I want to take data (olddata) that looks like this
> ID Day
> 1 1
> 1 1
> 1 2
> 1 2
> 1 3
>
2024 Jan 04
1
Obtaining a value of pie in a zero inflated model (fm-zinb2)
Are you referring to the zeroinfl() function in the countreg package? If
so, I think
predict(fm_zinb2, type = "zero", newdata = some.new.data)
will give you pi for each combination of covariate values that you
provide in some.new.data
where pi is the probability to observe a zero from the point mass component.
As to your second question, I'm not sure that's possible, for any
2024 Nov 27
1
R Processing dataframe by group - equivalent to SAS by group processing with a first. and retain statments
On 11/27/24 08:30, Sorkin, John wrote:
> I am an old, long time SAS programmer. I need to produce R code that processes a dataframe in a manner that is equivalent to that produced by using a by statement in SAS and an if first.day statement and a retain statement:
>
> I want to take data (olddata) that looks like this
> ID Day
> 1 1
> 1 1
> 1 2
> 1 2
> 1 3
> 1 3
>