[R] Request for some help about uncertainty analysis using bootstrap approach

2022-05-30 Thread Bhaskar Mitra
Hello Everyone,

I have a query about uncertainty analysis and would really appreciate some
help  in this regard.

I intend to gapfill the NAs in the “X” column of the dataframe (Df1). I
have grouped the data using the column “Group” ,
determined the mean and generated the “Z” column.

While I am using the mean and standard error approach to generate the
uncertainty analysis, can we use the bootstrap approach to
generate the uncertainty for the “Z” column? Any help in this regard will
be really appreciated.

Regards,
Bhaskar
---

Df1 <-

Group XYZ
1   2  3 2
1  NA3 3
13 3 3
1   4  34
22 21
2  NA23
2   NA   23
24 24
3 222
3 NA 2 2
3  2   2 2

---
Codes:

Df1 <- Df1 %>% group_by(Group) %>% summarise(Y= mean(X), na.rm=T)

Df1  <- Df1%>% mutate(Z= coalesce(X,Y))

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Converting data from weekly interval to daily interval

2021-06-08 Thread Bhaskar Mitra
Hello Everyone,

I have data at weekly intervals.
The data structure is something like this.

df1 <-
datea
1/7/2020 3
1/14/2020   6
1/21/2021   7

I would like to convert the data from the weekly
interval to the daily interval. Something like this.

datea
1/7/20200.5
1/8/20200.3
1/9/20200.7


I am using the following codes

d1 <- nrow(df1)

df2 <- data.frame(matrix(NA, nrow = (d1)*7, ncol = 1)

inc <- 0
for (i in 1:nrow(df1)) {
  for (j in 1:7) {
inc <- inc + 1
df2[inc,1] <- df1[i,1]/7
  }
}
rm(df1)



However, the sum of the daily values generated in df2 differ
from the original value in the df1 data frame. There is a 1-2% discrepancy.
I would appreciate it if someone could suggest how to improve the codes.

Thanks,
Bhaskar

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help in modifying code to extract data from url

2021-06-08 Thread Bhaskar Mitra
Thanks everyone for the feedbacks. This is really helpful.

bhaskar

On Sat, May 22, 2021 at 11:56 AM David Winsemius 
wrote:

> Several authors hav addressed this problem with names that resemble
> "rbindfill". In my machine I find four instances:
>
> ??rbindfill
>
> Help pages:
> ffbase::ffdfrbind.fillrbind for ffdf where missing columns are
> added if not available in one of the ffdf objects
> plyr::rbind.fillCombine data.frames by row, filling in missing
> columns.
> plyr::rbind.fill.matrixBind matrices by row, and fill missing
> columns with NA.
> rockchalk::rbindFillStack together data frames
>
>
> --
>
> David.
>
> On 5/20/21 2:19 AM, Jim Lemon wrote:
> > Hi Bhaskar,
> > If you are using read.table or similar, see the "fill=" argument.
> >
> > Jim
> >
> > On Thu, May 20, 2021 at 9:54 AM Bhaskar Mitra 
> wrote:
> >> Hello Everyone,
> >>
> >> I am trying to extract data from a url. The codes work well when the
> >> data structure is as follows:
> >>
> >> X Y
> >> 1 2
> >> 1 5
> >> 1 6
> >> 1 7
> >> 3 4
> >>
> >> However, the code fails when the data structure has no number
> >> under the 2nd column (shown below).I get the following error:
> >>
> >> "Error in data.frame(..., check.names = FALSE) :
> >>arguments imply differing number of rows: 242, 241"
> >>
> >>
> >> X Y
> >> 1 2
> >> 1
> >> 1
> >> 1 7
> >> 3 4
> >>
> >> Can anyone please help me in how I can modify the codes ( shown below)
> to
> >> adjust for the above mentioned condition
> >> in the data structure.
> >>
> >> library(rjson)
> >>
> >> url <- "abcd.com"
> >> json_data <- fromJSON(file= url)
> >> d3 <- lapply(json_data[[2]], function(x) c(x["data"]))
> >> d3 <- do.call(rbind, d3)
> >> X_Dataframe = as.data.frame(unlist(d3[[1]]))
> >> b <- do.call("cbind", split(X_Dataframe, rep(c(1, 2), length.out =
> >> nrow(X_Dataframe
> >>
> >>
> >> regards,
> >> bhaskar
> >>
> >>  [[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Help in modifying code to extract data from url

2021-05-19 Thread Bhaskar Mitra
Hello Everyone,

I am trying to extract data from a url. The codes work well when the
data structure is as follows:

X Y
1 2
1 5
1 6
1 7
3 4

However, the code fails when the data structure has no number
under the 2nd column (shown below).I get the following error:

"Error in data.frame(..., check.names = FALSE) :
  arguments imply differing number of rows: 242, 241"


X Y
1 2
1
1
1 7
3 4

Can anyone please help me in how I can modify the codes ( shown below) to
adjust for the above mentioned condition
in the data structure.

library(rjson)

url <- "abcd.com"
json_data <- fromJSON(file= url)
d3 <- lapply(json_data[[2]], function(x) c(x["data"]))
d3 <- do.call(rbind, d3)
X_Dataframe = as.data.frame(unlist(d3[[1]]))
b <- do.call("cbind", split(X_Dataframe, rep(c(1, 2), length.out =
nrow(X_Dataframe


regards,
bhaskar

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Request for help to modify sliderInput in RShiny app (conditional statement)

2020-11-17 Thread Bhaskar Mitra
Hello Everyone,

I have written certain codes in RShiny app which works fine.
There are 3 tabs, "Z1", "Z2" and "Z3".  Currently the sliderinput shows up
when I click all the 3 tabs.

I need  to adjust this code so that sliderInput is only visible when i
click  tab "Z1" and not for tabs "Z2" and "Z3".
 Can anyone please suggest how to modify the codes in that regard?

the codes for ui.r and server.r are given below.

thanks for your help,
regards,
bhaskar




#Codes for ui.r

library(shiny)
library(shinydashboard)
library(shinyjs)

fluidPage(

  sidebarLayout(position = "left",
sidebarPanel(
  sliderInput(inputId = "year",
  label = "Years included",
  min = 1990,
  max = 2000,
  value = c(1990, 2000),
  sep = "",
  step = 1),

  column(width = 10, plotOutput("distPlot"))

),

mainPanel(
  tabsetPanel(type = "pills",
  position = "below",
  tabPanel("Z1", plotOutput("trend")),
  tabPanel("Z2", plotOutput("trend1")),
  tabPanel("Z3", plotOutput("trend2"))
  ),
)
  )
)

#Codes for server.r

#library(ggthemes)
library(gapminder)
library(leaflet)
library(ggmap)
library(tidyverse)
library(lubridate)
library(fpp2)
library(zoo)
library(shinydashboard)
library(shinyjs)
library(ggpubr)

df7 =  read_csv("data.csv")
df8 = read_csv("data1.csv")

function(input, output) {

theData = reactive({
df7 %>%
  filter(year >= input$year[1], year <= input$year[2])
 })

  theData1 = reactive({df8})

output$trend = renderPlot
  ({
lp1 <- theData() %>%
  gather(metric, value, x1) %>%
  ggplot(aes(date, value, color = metric)) +
  geom_line()
print(lp1)
  })

  output$trend1 = renderPlot
  ({
lp2 <- theData1() %>%
  gather(metric, value, x2) %>%
  ggplot(aes(date, value, color = metric)) +
  geom_line()
print(lp2)
  })

  output$trend2 = renderPlot
  ({
lp3 <- theData1() %>%
  gather(metric, value, x3) %>%
  ggplot(aes(date, value, color = metric)) +
  geom_line()
print(lp3)
  })

}

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Help to download data from multiple URLs with API key

2020-04-22 Thread Bhaskar Mitra
Hi Eric,

Thanks for your help. This is really helpful.
I have also adjusted the code to ensure  filename has the
base url and suffix as strings.

thanks,
bhaskar

On Tue, Apr 21, 2020 at 12:16 AM Eric Berger  wrote:

> Hi Bhaskar,
> Why not just create a function that does the repetitive work, such as
>
> doOne <- function( suffix ) {
>base_url <- "abcd" # This remains constant
>b <-  "api_key"# the api key - this remains constant
>c <-  paste("series_id=",suffix,sep="")
>full_url = paste0(base_url, b, c)
>d3 <- lapply(fromJSON(file=full_url)[[2]], function(x) c(x["data"]))
>d3 <- do.call(rbind, d3)
>b <- as.data.frame(unlist(d3))
>write.csv(b)
> }
>
> Then,
> suffixes <- ... (whatever)
> for ( s in suffixes )
> doOne( s )
>
> You might need to also think about the filenames that you want to use in
> the write.csv() command in the function doOne.
>
> HTH,
> Eric
>
>
> On Tue, Apr 21, 2020 at 9:30 AM Bhaskar Mitra 
> wrote:
>
>> Hello Everyone,
>>
>> I am trying to download data from multiple websites using API key.
>> The  code to download from one URL is given below.
>>
>> I have a list of multiple URLs' where the suffix URL 'c' keeps changing.
>>
>> I would appreciate any help on how i can modify the code below that will
>> allow
>>  me to read multiple URLs and save the data from each URL as separate
>> csv file.
>>
>> thanks,
>> bhaskar
>>
>>
>> #---
>> library(rjson)
>> setwd(Input)
>>
>> base_url <- "abcd" # This remains constant
>>
>> b <-  "api_key"# the api key - this remains constant
>>
>> c <-  "series_id=1"# Only this suffix URL changes.  I have a list
>> of multiple such URL's with different series ids.
>>
>>
>> full_url = paste0(base_url,
>>   b,
>>   c)
>>
>>
>> d3 <- lapply(fromJSON(file=full_url)[[2]], function(x) c(x["data"]))
>> d3 <- do.call(rbind, d3)
>>
>> b <- as.data.frame(unlist(d3))
>> write.csv(b)
>>
>> #---
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Help to download data from multiple URLs with API key

2020-04-21 Thread Bhaskar Mitra
Hello Everyone,

I am trying to download data from multiple websites using API key.
The  code to download from one URL is given below.

I have a list of multiple URLs' where the suffix URL 'c' keeps changing.

I would appreciate any help on how i can modify the code below that will
allow
 me to read multiple URLs and save the data from each URL as separate
csv file.

thanks,
bhaskar


#---
library(rjson)
setwd(Input)

base_url <- "abcd" # This remains constant

b <-  "api_key"# the api key - this remains constant

c <-  "series_id=1"# Only this suffix URL changes.  I have a list
of multiple such URL's with different series ids.


full_url = paste0(base_url,
  b,
  c)


d3 <- lapply(fromJSON(file=full_url)[[2]], function(x) c(x["data"]))
d3 <- do.call(rbind, d3)

b <- as.data.frame(unlist(d3))
write.csv(b)

#---

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Request for help about running a loop and reading .NC files

2020-03-24 Thread Bhaskar Mitra
Hello Everyone,

I have written a loop which reads hundreds of .nc files
and extract information from each .nc file and
exports that corresponding information as a csv file.

The loop works fine until it encounters a .nc file which it cannot read
and the loop stops.

 I would appreciate if anyone can suggest how can I modify
the loop, whereby the loop will continue to run by bypassing those
particular
files which it cannot read or if any particular file has an error.

In the end, I was also hoping to modify the loop such that it
will generate a report which will inform me which
files were not read by the loop.  The codes are given below

Thanks for your help,

Regards,
Bhaskar Mitra


#_--


library(ncdf4)
library(reshape2)
library(dplyr)
library(stringr)


setwd("directory path")

Output <- "directory path"

flist <- list.files(path ="NCFiles/", pattern = "^.*\\.(nc|NC|Nc|Nc)$")

for (i in 1: length(flist))
{

  nc <- nc_open(paste0("NCFiles/",flist[i]))
  mean1 <- ncvar_get(nc,attributes(nc$dim)$names[3])
  nc_close(nc)

  mean_chl_df <- melt(mean1)
  trial.table.df <-as.data.frame(mean_chl_df)

write.csv(trial.table.df,paste0(Output,"/",tools::file_path_sans_ext(flist[i]),".csv"))

}

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Help with creating subset of a data frame

2018-07-09 Thread Bhaskar Mitra
Hello Everyone,

I am trying to create a subset of a data frame (df1) based on the first
three
unique values in the first column (v1).

Here are my codes:

b <- unique(df1$v1)[1:3]
df2 <- subset(df1,df1$v1==b)

df1:
v1   v2v3
1 ab
1 a1   b1
2 a2   b2
2 a3   b3
3 a4   b4
3 a5   b5
3 a6   b6
4 a7   b7
4 a8   b8
4 a9   b9
5 a10  b10
5 a11  b11
5 a12  b12
5 a13  b13


Ideally, I want my new dataframe (df2) to look something like this:


df2:
v1   v2v3
1 ab
1 a1   b1
2 a2   b2
2 a3   b3
3 a4   b4
3 a5   b5
3 a6   b6



However, that doesn't seem to be the case and i am getting the following
warning message:

Warning message:
In df1$v1==b :  longer object length is not a multiple of shorter object
length


I would appreciate any help in this regard,

sincerely,
bhaskar

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Request for help - adding text files to a data frame

2017-06-25 Thread Bhaskar Mitra
Hello Everyone,

I have a data frame which looks something like this:

V1 <-c(1,2,3)
V2 <-c(5,6,7)
V3 <-c(9,10,11)

 df <- data.frame(V1,V2,V3)

I want to add couple of text files at the beginning of df and save
the df as a csv file.


The csv file should look something like this:

""
"B"
"C"
V1  V2 V3
15  9
26   10
37   11


Any suggestions/advice in this regard.

Thanks for your help,
Bhaskar

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Query - Merging and conditional replacement of values in a data frame

2017-02-12 Thread Bhaskar Mitra
Thanks for all your help. This is helpful.

Best,
Bhaskar

On Sun, Feb 12, 2017 at 4:35 AM, Jim Lemon <drjimle...@gmail.com> wrote:

> Hi Bhaskar,
> Maybe:
>
> df1 <-read.table(text="time v1  v2 v3
> 1 2   3  4
> 2 5   6  4
> 3 1   3  4
> 4 1   3  4
> 5 2   3  4
> 6 2   3  4",
> header=TRUE)
>
>
> df2 <-read.table(text="time v11  v12 v13
> 3 112   3  4
> 4 112   3  4",
> header=TRUE)
>
> for(time1 in df1$time) {
>  time2<-which(df2$time==time1)
>  if(length(time2)) df1[df1$time==time1,]<-df2[time2,]
> }
>
> Jim
>
>
> On Sun, Feb 12, 2017 at 11:13 AM, Bhaskar Mitra
> <bhaskar.kolk...@gmail.com> wrote:
> > Hello Everyone,
> >
> > I have two data frames df1 and df2 as shown below. They
> > are of different length. However, they have one common column - time.
> >
> > df1 <-
> > time v1  v2 v3
> > 1 2   3  4
> > 2 5   6  4
> > 3 1   3  4
> > 4 1   3  4
> > 5 2   3  4
> > 6 2   3  4
> >
> >
> > df2 <-
> > time v11  v12 v13
> > 3 112   3  4
> > 4 112   3  4
> >
> > By matching the 'time' column in df1 and df2, I am trying to modify
> column
> > 'v1' in df1 by replacing it
> > with values in column 'v11' in df2. The modified df1 should look
> something
> > like this:
> >
> > df1 <-
> > time v1   v2 v3
> > 1 2   3  4
> > 2 5   6  4
> > 3 112 3  4
> > 4 112 3  4
> > 5 2   3  4
> > 6 2   3  4
> >
> > I tried to use the 'merge' function to combine df1 and df2 followed by
> > the conditional 'ifelse' statement. However, that doesn't seem to work.
> >
> > Can I replace the values in df1 by not merging the two data frames?
> >
> > Thanks for your help,
> >
> > Regards,
> > Bhaskar
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Query - Merging and conditional replacement of values in a data frame

2017-02-11 Thread Bhaskar Mitra
Hello Everyone,

I have two data frames df1 and df2 as shown below. They
are of different length. However, they have one common column - time.

df1 <-
time v1  v2 v3
1 2   3  4
2 5   6  4
3 1   3  4
4 1   3  4
5 2   3  4
6 2   3  4


df2 <-
time v11  v12 v13
3 112   3  4
4 112   3  4

By matching the 'time' column in df1 and df2, I am trying to modify column
'v1' in df1 by replacing it
with values in column 'v11' in df2. The modified df1 should look something
like this:

df1 <-
time v1   v2 v3
1 2   3  4
2 5   6  4
3 112 3  4
4 112 3  4
5 2   3  4
6 2   3  4

I tried to use the 'merge' function to combine df1 and df2 followed by
the conditional 'ifelse' statement. However, that doesn't seem to work.

Can I replace the values in df1 by not merging the two data frames?

Thanks for your help,

Regards,
Bhaskar

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Time format lagging issue

2016-09-14 Thread Bhaskar Mitra
Thanks for all your feedbacks. This is helpful.

My apologies for any inconvenience due to asterisks.

Thanks,
Bhaskar

On Wed, Aug 31, 2016 at 6:09 PM, William Dunlap <wdun...@tibco.com> wrote:

> That
>   tmp1 - 30*60
> can also be done as
>   tmp1 - as.difftime(30, units="mins")
> so you don't have to remember that the internal representation of POSIXct
> is seconds since the start of 1970.  You can choose from the following
> equivalent expressions.
>   tmp1 - as.difftime(0.5, units="hours")
>   tmp1 - as.difftime(1/2 * 1/24, units="days")
>   tmp1 - as.difftime(30*60, units="secs")
>   tmp1 - as.difftime(1/2 * 1/24 * 1/7, units="weeks")
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Wed, Aug 31, 2016 at 2:44 PM, MacQueen, Don <macque...@llnl.gov> wrote:
>
>> Try following this example:
>>
>> mydf <- data.frame(t1=c('201112312230', '201112312330'))
>> tmp1 <- as.POSIXct(mydf$t1, format='%Y%m%d%H%M')
>> tmp2 <- tmp1 - 30*60
>> mydf$t2 <- format(tmp2, '%Y%m%d%H%M')
>>
>> It can be made into a single line, but I used intermediate variables tmp1
>> and tmp2 so that it would be easier to follow.
>>
>> Base R is more than adequate for this task.
>>
>> Please get rid of the asterisks in your next email. The just get in the
>> way. Learn how to send plain text email, not HTML email. Please.
>>
>>
>>
>>
>> --
>> Don MacQueen
>>
>> Lawrence Livermore National Laboratory
>> 7000 East Ave., L-627
>> Livermore, CA 94550
>> 925-423-1062
>>
>>
>>
>>
>>
>> On 8/31/16, 9:07 AM, "R-help on behalf of Bhaskar Mitra"
>> <r-help-boun...@r-project.org on behalf of bhaskar.kolk...@gmail.com>
>> wrote:
>>
>> >Hello Everyone,
>> >
>> >I am trying a shift the time series in a dataframe (df) by 30 minutes .
>> My
>> >current format looks something like this :
>> >
>> >
>> >
>> >*df$$Time 1*
>> >
>> >
>> >*201112312230*
>> >
>> >*201112312300*
>> >
>> >*201112312330*
>> >
>> >
>> >
>> >*I am trying to add an additional column of time (df$Time 2) next to
>> Time
>> >1 by lagging it by ­ 30minutes. Something like this :*
>> >
>> >
>> >*df$Time1   **df$$Time2*
>> >
>> >
>> >*201112312230  **201112312200*
>> >
>> >*201112312300  **201112312230*
>> >
>> >*201112312330  **201112312300*
>> >
>> >*201112312330  *
>> >
>> >
>> >
>> >
>> >
>> >*Based on some of the suggestions available, I have tried this option *
>> >
>> >
>> >
>> >*require(zoo)*
>> >
>> >*df1$Time2  <- lag(df1$Time1, -1, na.pad = TRUE)*
>> >
>> >*View(df1)*
>> >
>> >
>> >
>> >*This does not however give me the desired result. I would appreciate any
>> >suggestions/advice in this regard.*
>> >
>> >
>> >*Thanks,*
>> >
>> >*Bhaskar*
>> >
>> >   [[alternative HTML version deleted]]
>> >
>> >__
>> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> >https://stat.ethz.ch/mailman/listinfo/r-help
>> >PLEASE do read the posting guide
>> >http://www.R-project.org/posting-guide.html
>> >and provide commented, minimal, self-contained, reproducible code.
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] Time format lagging issue

2016-08-31 Thread Bhaskar Mitra
Hello Everyone,

I am trying a shift the time series in a dataframe (df) by 30 minutes . My
current format looks something like this :



*df$$Time 1*


*201112312230*

*201112312300*

*201112312330*



*I am trying to add an additional column of time (df$Time 2) next to  Time
1 by lagging it by – 30minutes. Something like this :*


*df$Time1   **df$$Time2*


*201112312230  **201112312200*

*201112312300  **201112312230*

*201112312330  **201112312300*

*201112312330  *





*Based on some of the suggestions available, I have tried this option *



*require(zoo)*

*df1$Time2  <- lag(df1$Time1, -1, na.pad = TRUE)*

*View(df1)*



*This does not however give me the desired result. I would appreciate any
suggestions/advice in this regard.*


*Thanks,*

*Bhaskar*

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] Help in plotting

2016-07-31 Thread Bhaskar Mitra
Hello Everyone,


I have a data frame with 2 columns as shown at the end of this mail. I want
to plot the data in column A;
 however I want the  data-points in column A to be of different color based
on conditions in column B.
i.e all data in column A corresponding to value 0 in column B should be
red.
Similarly all values in column A corresponding to value 2 in column B
should be green.

Any suggestions or help in this regard.

Best,
Bhaskar





A   B
12  0
11  1
23  2
34  0
45  1
67  3
… ..

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] Issue with Transform function in R

2016-07-21 Thread Bhaskar Mitra
Hello Everyone,


I am trying to replace the values in the 2nd column (Variable 1)
corresponding to certain dates  (Date)


with NAs as shown below. Both Date and Variable1 are numeric vectors . I am
trying to use the transform function


as shown below but it doesn’t seem to work even though if I am not getting
any error


Any suggestions/help in this regard?

regards,

-



Df1 <- data.frame(Date, Variable1)




a1 <- transform(Df1, ifelse(Date  > "010301000300 " && Date <
"010501000300", Variable1 ==NA, Variable1))


Original Data frame



 Date  Variable1

010101000300 1

010201000300 2

010301000300 3

010401000300 4

010501000300 5

010601000300 6

010701000300 7

 .

.

.

……….




Transformed data frame (i hope to transform)



  Date   Variable1

0101010003001

0102010003002

010301000300   NA

010401000300   NA

010501000300NA

0106010003006

0107010003007



……….

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] Merging 2 files with different timestamp

2016-05-22 Thread Bhaskar Mitra
Hello, I am trying to merge two text files by using the timestamp
header for both the files:

The first file has the following format for the timestamp:"2012-01-01
23:30:00 UTC"

Timestamp for the second file : 2012-01-01 2330.

I am having problems by converting from one timestamp format to another.
Any suggestions/help in this regard?

regards,

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Merging 2 files with different timestamp

2016-05-22 Thread Bhaskar Mitra
Hello,

My apologies for the earlier posting. There was an error with regard to my
query :


I am trying to merge two text files by using the timestamp
header for both the files:

The first file has the following format for the timestamp:"27-Dec-12 23H
30M 0S"

Timestamp for the second file : 2012-12-27 2330.

I am having problems by converting from one timestamp format to another.
Any suggestions/help in this regard?

regards,




On Sun, May 22, 2016 at 12:40 PM, Bhaskar Mitra <bhaskar.kolk...@gmail.com>
wrote:

> Hello, I am trying to merge two text files by using the timestamp
> header for both the files:
>
> The first file has the following format for the timestamp:"2012-01-01
> 23:30:00 UTC"
>
> Timestamp for the second file : 2012-01-01 2330.
>
> I am having problems by converting from one timestamp format to another.
> Any suggestions/help in this regard?
>
> regards,
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.