Hi List Members,
This is a very stupid problem but I am not able to know what the solution
can be.
I am trying to run a query like below
*Program Flow :*
1. a <- data.frame(table( cut( Sys.time() + seq(0,82800,3600), "60
mins")
)) # It generates the 60 minute intervals. Thanks David
2. b <- data.frame(a$Var1)
# To extract only First Column i.e. Var1
3. class(b)
# checking class
4. b[1:1,1:1]
# Trying to access the first row and the
problem starts.
2. b <- Sys.time()+ 5*60
# 5 minute interval increase
3. ifelse(b[1:1,1:1] *"<" *Sys.time()+5*60,rnorm(1,0,5),Sys.sleep)
Error: unexpected string constant in "ifelse(b[2:2,1:1] "<"
My only aim is to run "ifelse" for checking whether the program is
running
or not.Please help
*Data :*
a <- structure(list(Var1 = structure(1:24, .Label = c("2012-09-19
16:40:00",
"2012-09-19 17:40:00", "2012-09-19 18:40:00",
"2012-09-19 19:40:00",
"2012-09-19 20:40:00", "2012-09-19 21:40:00",
"2012-09-19 22:40:00",
"2012-09-19 23:40:00", "2012-09-20 00:40:00",
"2012-09-20 01:40:00",
"2012-09-20 02:40:00", "2012-09-20 03:40:00",
"2012-09-20 04:40:00",
"2012-09-20 05:40:00", "2012-09-20 06:40:00",
"2012-09-20 07:40:00",
"2012-09-20 08:40:00", "2012-09-20 09:40:00",
"2012-09-20 10:40:00",
"2012-09-20 11:40:00", "2012-09-20 12:40:00",
"2012-09-20 13:40:00",
"2012-09-20 14:40:00", "2012-09-20 15:40:00"), class =
"factor"),
Freq = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)), .Names =
c("Var1",
"Freq"), row.names = c(NA, -24L), class = "data.frame")
*Session Info *
R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices datasets utils
[6] methods base
other attached packages:
[1] rcom_2.2-5 rscproxy_2.0-5
loaded via a namespace (and not attached):
[1] tools_2.15.1
Best Regards,
Bhupendrasinh Thakre
*Disclaimer :*
The information contained in this communication is confi...{{dropped:11}}
Hi,
Try this:
a <- data.frame(table( cut( Sys.time() + seq(0,82800,3600), "60
mins")
b <- data.frame(a$Var1)
?str(b)
#'data.frame':??? 24 obs. of? 1 variable:
# $ a.Var1: Factor w/ 24 levels "2012-09-19 18:03:00",..: 1 2 3 4 5 6
7 8 9 1
b1<-within(b,{a.Var1<-as.POSIXct(a.Var1,format="%Y-%m-%d
%H:%M:%S")})
b1[1,]
#[1] "2012-09-19 18:03:00 EDT"
Sys.time()+5*60
#[1] "2012-09-19 18:25:55 EDT"
set.seed(1)
?ifelse(b1[1,]< (Sys.time()+5*60),rnorm(1,0,5),Sys.sleep)
#[1] -3.132269
A.K.
----- Original Message -----
From: Bhupendrasinh Thakre <vickythakre at gmail.com>
To: R help <r-help at r-project.org>
Cc:
Sent: Wednesday, September 19, 2012 5:54 PM
Subject: [R] Data Frame (Very Simple Problem)
Hi List Members,
This is a very stupid problem but I am not able to know what the solution
can be.
I am trying to run a query like below
*Program Flow :*
1. a <- data.frame(table( cut( Sys.time() + seq(0,82800,3600), "60
mins")
))? ? ? # It generates the 60 minute intervals. Thanks David
2. b <- data.frame(a$Var1)
? ? ? ? ? ? ? ? ? ? ? ? ? # To extract only First Column i.e. Var1
3. class(b)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # checking class
4. b[1:1,1:1]
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # Trying to access the first row and the
problem starts.
2. b <-? Sys.time()+ 5*60
? ? ? ? ? ? ? ? ? ? ? ? # 5 minute interval increase
3. ifelse(b[1:1,1:1] *"<" *Sys.time()+5*60,rnorm(1,0,5),Sys.sleep)
Error: unexpected string constant in "ifelse(b[2:2,1:1] "<"
My only aim is to run "ifelse" for checking whether the program is
running
or not.Please help
*Data :*
a <- structure(list(Var1 = structure(1:24, .Label = c("2012-09-19
16:40:00",
"2012-09-19 17:40:00", "2012-09-19 18:40:00",
"2012-09-19 19:40:00",
"2012-09-19 20:40:00", "2012-09-19 21:40:00",
"2012-09-19 22:40:00",
"2012-09-19 23:40:00", "2012-09-20 00:40:00",
"2012-09-20 01:40:00",
"2012-09-20 02:40:00", "2012-09-20 03:40:00",
"2012-09-20 04:40:00",
"2012-09-20 05:40:00", "2012-09-20 06:40:00",
"2012-09-20 07:40:00",
"2012-09-20 08:40:00", "2012-09-20 09:40:00",
"2012-09-20 10:40:00",
"2012-09-20 11:40:00", "2012-09-20 12:40:00",
"2012-09-20 13:40:00",
"2012-09-20 14:40:00", "2012-09-20 15:40:00"), class =
"factor"),
? ? Freq = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
? ? 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)), .Names =
c("Var1",
"Freq"), row.names = c(NA, -24L), class = "data.frame")
*Session Info *
R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats? ? graphics? grDevices datasets? utils
[6] methods? base
other attached packages:
[1] rcom_2.2-5? ? rscproxy_2.0-5
loaded via a namespace (and not attached):
[1] tools_2.15.1
Best Regards,
Bhupendrasinh Thakre
*Disclaimer :*
The information contained in this communication is confi...{{dropped:11}}
______________________________________________
R-help at r-project.org mailing list
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.
Hello, Your code is reproducible and completely explains the issue, thanks. First I had the impression of a well organized question. Then I've read point 4. 4. The sequence 1:1 starts and ends at 1. You don't need b[1:1, 1:1], b[1, 1] will do. Then you assign a different value to 'b'. This time it's a vector, not a data.frame. The ifelse corrected is # 'b' is now 1-dim ifelse(b[1] < Sys.time()+5*60, rnorm(1,0,5), Sys.sleep) (Why the '*' and the double quotes?) Then I've realized that you had restarted the counting, but starting with point 2. Hope this helps, Rui Barradas Em 19-09-2012 22:54, Bhupendrasinh Thakre escreveu:> Hi List Members, > > This is a very stupid problem but I am not able to know what the solution > can be. > I am trying to run a query like below > > *Program Flow :* > > 1. a <- data.frame(table( cut( Sys.time() + seq(0,82800,3600), "60 mins") > )) # It generates the 60 minute intervals. Thanks David > 2. b <- data.frame(a$Var1) > # To extract only First Column i.e. Var1 > 3. class(b) > # checking class > 4. b[1:1,1:1] > # Trying to access the first row and the > problem starts. > 2. b <- Sys.time()+ 5*60 > # 5 minute interval increase > 3. ifelse(b[1:1,1:1] *"<" *Sys.time()+5*60,rnorm(1,0,5),Sys.sleep) > > Error: unexpected string constant in "ifelse(b[2:2,1:1] "<" > > My only aim is to run "ifelse" for checking whether the program is running > or not.Please help > > *Data :* > > a <- structure(list(Var1 = structure(1:24, .Label = c("2012-09-19 > 16:40:00", > "2012-09-19 17:40:00", "2012-09-19 18:40:00", "2012-09-19 19:40:00", > "2012-09-19 20:40:00", "2012-09-19 21:40:00", "2012-09-19 22:40:00", > "2012-09-19 23:40:00", "2012-09-20 00:40:00", "2012-09-20 01:40:00", > "2012-09-20 02:40:00", "2012-09-20 03:40:00", "2012-09-20 04:40:00", > "2012-09-20 05:40:00", "2012-09-20 06:40:00", "2012-09-20 07:40:00", > "2012-09-20 08:40:00", "2012-09-20 09:40:00", "2012-09-20 10:40:00", > "2012-09-20 11:40:00", "2012-09-20 12:40:00", "2012-09-20 13:40:00", > "2012-09-20 14:40:00", "2012-09-20 15:40:00"), class = "factor"), > Freq = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("Var1", > "Freq"), row.names = c(NA, -24L), class = "data.frame") > > *Session Info * > > R version 2.15.1 (2012-06-22) > Platform: i386-pc-mingw32/i386 (32-bit) > > locale: > [1] LC_COLLATE=English_United States.1252 > [2] LC_CTYPE=English_United States.1252 > [3] LC_MONETARY=English_United States.1252 > [4] LC_NUMERIC=C > [5] LC_TIME=English_United States.1252 > > attached base packages: > [1] stats graphics grDevices datasets utils > [6] methods base > > other attached packages: > [1] rcom_2.2-5 rscproxy_2.0-5 > > loaded via a namespace (and not attached): > [1] tools_2.15.1 > > Best Regards, > > > Bhupendrasinh Thakre > > *Disclaimer :* > > The information contained in this communication is confi...{{dropped:11}} > > ______________________________________________ > R-help at r-project.org mailing list > 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.