Re: [R] R Data

2019-02-14 Thread Fowler, Mark
Hi Spencer,

The an1 syntax is adding regression coefficients (or NAs where a regression 
could not be done) to the downloaded and processed data, which ends up a 
matrix. The cbind function adds the regression coefficients to the last column 
of the matrix (i.e. bind the columns of the inputs in the order given). Simple 
example below. Not actually any need for the separate cbind commands, could 
have just used an1=cbind(an,p,t). The cbind function expects all the columns to 
be of the same length, hence the use of the tryCatch function to capture NA's 
for failed regression attempts, ensuring that p and t correspond row by row 
with the matrix.

 x=seq(1,5)
 y=seq(6,10)
 z=seq(1,5)
xyz=cbind(x,y,z)
xyz
   x  y z
[1,] 1  6 1
[2,] 2  7 2
[3,] 3  8 3
[4,] 4  9 4
[5,] 5 10 5
dangs=rep(NA,5)
xyzd=cbind(xyz,dangs)
xyzd
 x  y z dangs
[1,] 1  6 1NA
[2,] 2  7 2NA
[3,] 3  8 3NA
[4,] 4  9 4NA
[5,] 5 10 5NA

-Original Message-
From: R-help  On Behalf Of Spencer Brackett
Sent: February 14, 2019 12:32 AM
To: R-help ; Sarah Goslee ; 
Caitlin Gibbons ; Jeff Newmiller 

Subject: [R] R Data

Hello everyone,

The following is a portion of coding that a colleague sent. Given my lack of 
experience in R, I am not quite sure what the significance of the following 
arguments. Could anyone help me translate? For context, I am aware of the 
downloading portion of the script... library(data.table) etc., but am not 
familiar with the portion pertaining to an1 .

library(data.table)
anno = as.data.frame(fread(file =
"/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", sep ="\t", 
header = T)) meth = read.table(file = 
"/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/27K/GBM.txt", sep  ="\t", header = 
T, row.names = 1) meth = as.matrix(meth) """ the loop just formats the 
methylation column names to match format"""
colnames(meth) = sapply(colnames(meth), function(i){
  c1 = strsplit(i,split = '.', fixed = T)[[1]]
  c1[4] = paste(strsplit(c1[4],split = "",fixed = T)[[1]][1:2],collapse =
"")
  paste(c1,collapse = ".")
})
exp = read.table(file =
"/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/RNAseq/GBM.txt", sep = "\t", 
header = T, row.names = 1) exp = as.matrix(exp) c = 
intersect(colnames(exp),colnames(meth))
exp = exp[,c]
meth = meth[,c]
m = apply(meth, 1, function(i){
  log2(i/(1-i))
})
m = t(as.matrix(m))
an = anno[anno$probe %in% rownames(m),]
an = an[an$gene %in% rownames(exp),]
an = an[an$location %in% c("TSS200","TSS1500"),]

p = apply(an,1,function(i){
  tryCatch(summary(lm(exp[as.character(i[2]),] ~ 
m[as.character(i[1]),]))$coefficient[2,4], error= function(e)NA)
})
t = apply(an,1,function(i){
  tryCatch(summary(lm(exp[as.character(i[2]),] ~ 
m[as.character(i[1]),]))$coefficient[2,3], error= function(e)NA)
})
an1 =cbind(an,p)
an1 = cbind(an1,t)
an1$q = p.adjust(as.numeric(an1$p))
summary(lm(exp["MAOB",] ~ m["cg00121904",]$coefficient[2,c(3:4)]
###

[[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.


Re: [R] pattern evaluation in electron microscopy images

2019-02-14 Thread PIKAL Petr
Hallo Steve.

Thank you for pointing to ImageJ, I will try to inspect it. I expected that 
somebody in R comunity automated such procedure within some R package, but it 
is probably too specialised.

S pozdravem | Best Regards
RNDr. Petr PIKAL
Vedoucí Výzkumu a vývoje | Research Manager
PRECHEZA a.s.
nábř. Dr. Edvarda Beneše 1170/24 | 750 02 Přerov | Czech Republic
Tel: +420 581 252 256 | GSM: +420 724 008 364
petr.pi...@precheza.cz | www.precheza.cz

Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních 
partnerů PRECHEZA a.s. jsou zveřejněny na: 
https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about 
processing and protection of business partner's personal data are available on 
website: https://www.precheza.cz/en/personal-data-protection-principles/
Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a 
podléhají tomuto právně závaznému prohlášení o vyloučení odpovědnosti: 
https://www.precheza.cz/01-dovetek/ | This email and any documents attached to 
it may be confidential and are subject to the legally binding disclaimer: 
https://www.precheza.cz/en/01-disclaimer/

> -Original Message-
> From: S Ellison 
> Sent: Monday, February 11, 2019 12:54 PM
> To: PIKAL Petr ; r-help@r-project.org
> Subject: RE: pattern evaluation in electron microscopy images
> 
> Not really my field, but would you not approach this using FFT on selected
> regions?
> 
> I think IMageJ has some capability in that area; see example at
> https://imagej.nih.gov/ij/docs/examples/tem/.
> 
> Steve Ellison
> 
> 
> 
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of PIKAL
> > Petr
> > Sent: 08 February 2019 09:54
> > To: r-help@r-project.org
> > Subject: [R] pattern evaluation in electron microscopy images
> >
> > Dear all
> >
> > I enclose 3 electron microscope images in which I would like to
> > evaluate plane spacing.
> >
> > Before I start to dig deeper and use trial and error in trying to find
> > some packages/functions for such pattern evaluation in electron
> > microscopy pictures I would like to ask if anybody could point me to
> > suitable packages/functions.
> >
> > I am aware of EBImage package for general purpose image manipulation,
> > but it does not have such functionality.
> >
> > Best regards
> > Petr
> >
> > If images did not came through please use this link:
> > Stáhnout
> > soubory > 6-
> > a77b-4ff6-8155-d9302e7b151b>.
> >
> > Osobní údaje: Informace o zpracování a ochraně osobních údajů
> > obchodních partnerů PRECHEZA a.s. jsou zveřejněny na:
> > https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information
> > about processing and protection of business partner's personal data
> > are available on website: https://www.precheza.cz/en/personal-data-
> > protection-principles/
> > Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou
> > důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení
> > odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any
> > documents attached to it may be confidential and are subject to the
> > legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/
> >
> > __
> > 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.
> 
> 
> *
> **
> This email and any attachments are confidential. Any u...{{dropped:10}}

__
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] R Data

2019-02-14 Thread Spencer Brackett
Mr. Fowler,

Thank you! This information is most helpful. So from my understanding, I
can use the regression coefficients shown (via the coding I originally
sent, to generate a continuous distribution with what is essentially a line
of best fit? The data added here had some 30,000 variables (it is genomic
data from TCGA), does this mean that any none NA data is being accounted
for in said distribution?

Best,

Spencer Brackett



On Thursday, February 14, 2019, Fowler, Mark 
wrote:

> Hi Spencer,
>
> The an1 syntax is adding regression coefficients (or NAs where a
> regression could not be done) to the downloaded and processed data, which
> ends up a matrix. The cbind function adds the regression coefficients to
> the last column of the matrix (i.e. bind the columns of the inputs in the
> order given). Simple example below. Not actually any need for the separate
> cbind commands, could have just used an1=cbind(an,p,t). The cbind function
> expects all the columns to be of the same length, hence the use of the
> tryCatch function to capture NA's for failed regression attempts, ensuring
> that p and t correspond row by row with the matrix.
>
>  x=seq(1,5)
>  y=seq(6,10)
>  z=seq(1,5)
> xyz=cbind(x,y,z)
> xyz
>x  y z
> [1,] 1  6 1
> [2,] 2  7 2
> [3,] 3  8 3
> [4,] 4  9 4
> [5,] 5 10 5
> dangs=rep(NA,5)
> xyzd=cbind(xyz,dangs)
> xyzd
>  x  y z dangs
> [1,] 1  6 1NA
> [2,] 2  7 2NA
> [3,] 3  8 3NA
> [4,] 4  9 4NA
> [5,] 5 10 5NA
>
> -Original Message-
> From: R-help  On Behalf Of Spencer Brackett
> Sent: February 14, 2019 12:32 AM
> To: R-help ; Sarah Goslee ;
> Caitlin Gibbons ; Jeff Newmiller <
> jdnew...@dcn.davis.ca.us>
> Subject: [R] R Data
>
> Hello everyone,
>
> The following is a portion of coding that a colleague sent. Given my lack
> of experience in R, I am not quite sure what the significance of the
> following arguments. Could anyone help me translate? For context, I am
> aware of the downloading portion of the script... library(data.table) etc.,
> but am not familiar with the portion pertaining to an1 .
>
> library(data.table)
> anno = as.data.frame(fread(file =
> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", sep ="\t",
> header = T)) meth = read.table(file = "/rsrch1/bcb/kchen_group/v_
> mohanty/data/TCGA/27K/GBM.txt", sep  ="\t", header = T, row.names = 1)
> meth = as.matrix(meth) """ the loop just formats the methylation column
> names to match format"""
> colnames(meth) = sapply(colnames(meth), function(i){
>   c1 = strsplit(i,split = '.', fixed = T)[[1]]
>   c1[4] = paste(strsplit(c1[4],split = "",fixed = T)[[1]][1:2],collapse =
> "")
>   paste(c1,collapse = ".")
> })
> exp = read.table(file =
> "/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/RNAseq/GBM.txt", sep = "\t",
> header = T, row.names = 1) exp = as.matrix(exp) c = intersect(colnames(exp),
> colnames(meth))
> exp = exp[,c]
> meth = meth[,c]
> m = apply(meth, 1, function(i){
>   log2(i/(1-i))
> })
> m = t(as.matrix(m))
> an = anno[anno$probe %in% rownames(m),]
> an = an[an$gene %in% rownames(exp),]
> an = an[an$location %in% c("TSS200","TSS1500"),]
>
> p = apply(an,1,function(i){
>   tryCatch(summary(lm(exp[as.character(i[2]),] ~ 
> m[as.character(i[1]),]))$coefficient[2,4],
> error= function(e)NA)
> })
> t = apply(an,1,function(i){
>   tryCatch(summary(lm(exp[as.character(i[2]),] ~ 
> m[as.character(i[1]),]))$coefficient[2,3],
> error= function(e)NA)
> })
> an1 =cbind(an,p)
> an1 = cbind(an1,t)
> an1$q = p.adjust(as.numeric(an1$p))
> summary(lm(exp["MAOB",] ~ m["cg00121904",]$coefficient[2,c(3:4)]
> ###
>
> [[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.


Re: [R] R Data

2019-02-14 Thread Fowler, Mark
I am not sure I would use the word ‘accounted’, more like discounted (tossed 
out).

From: Spencer Brackett 
Sent: February 14, 2019 9:21 AM
To: Fowler, Mark 
Cc: R-help ; Sarah Goslee ; 
Caitlin Gibbons ; Jeff Newmiller 

Subject: Re: R Data

Mr. Fowler,

Thank you! This information is most helpful. So from my understanding, I can 
use the regression coefficients shown (via the coding I originally sent, to 
generate a continuous distribution with what is essentially a line of best fit? 
The data added here had some 30,000 variables (it is genomic data from TCGA), 
does this mean that any none NA data is being accounted for in said 
distribution?

Best,

Spencer Brackett



On Thursday, February 14, 2019, Fowler, Mark 
mailto:mark.fow...@dfo-mpo.gc.ca>> wrote:
Hi Spencer,

The an1 syntax is adding regression coefficients (or NAs where a regression 
could not be done) to the downloaded and processed data, which ends up a 
matrix. The cbind function adds the regression coefficients to the last column 
of the matrix (i.e. bind the columns of the inputs in the order given). Simple 
example below. Not actually any need for the separate cbind commands, could 
have just used an1=cbind(an,p,t). The cbind function expects all the columns to 
be of the same length, hence the use of the tryCatch function to capture NA's 
for failed regression attempts, ensuring that p and t correspond row by row 
with the matrix.

 x=seq(1,5)
 y=seq(6,10)
 z=seq(1,5)
xyz=cbind(x,y,z)
xyz
   x  y z
[1,] 1  6 1
[2,] 2  7 2
[3,] 3  8 3
[4,] 4  9 4
[5,] 5 10 5
dangs=rep(NA,5)
xyzd=cbind(xyz,dangs)
xyzd
 x  y z dangs
[1,] 1  6 1NA
[2,] 2  7 2NA
[3,] 3  8 3NA
[4,] 4  9 4NA
[5,] 5 10 5NA

-Original Message-
From: R-help 
mailto:r-help-boun...@r-project.org>> On Behalf 
Of Spencer Brackett
Sent: February 14, 2019 12:32 AM
To: R-help mailto:r-help@r-project.org>>; Sarah Goslee 
mailto:sarah.gos...@gmail.com>>; Caitlin Gibbons 
mailto:bioprogram...@gmail.com>>; Jeff Newmiller 
mailto:jdnew...@dcn.davis.ca.us>>
Subject: [R] R Data

Hello everyone,

The following is a portion of coding that a colleague sent. Given my lack of 
experience in R, I am not quite sure what the significance of the following 
arguments. Could anyone help me translate? For context, I am aware of the 
downloading portion of the script... library(data.table) etc., but am not 
familiar with the portion pertaining to an1 .

library(data.table)
anno = as.data.frame(fread(file =
"/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/450K/mapper.txt", sep ="\t", 
header = T)) meth = read.table(file = 
"/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/27K/GBM.txt", sep  ="\t", header = 
T, row.names = 1) meth = as.matrix(meth) """ the loop just formats the 
methylation column names to match format"""
colnames(meth) = sapply(colnames(meth), function(i){
  c1 = strsplit(i,split = '.', fixed = T)[[1]]
  c1[4] = paste(strsplit(c1[4],split = "",fixed = T)[[1]][1:2],collapse =
"")
  paste(c1,collapse = ".")
})
exp = read.table(file =
"/rsrch1/bcb/kchen_group/v_mohanty/data/TCGA/RNAseq/GBM.txt", sep = "\t", 
header = T, row.names = 1) exp = as.matrix(exp) c = 
intersect(colnames(exp),colnames(meth))
exp = exp[,c]
meth = meth[,c]
m = apply(meth, 1, function(i){
  log2(i/(1-i))
})
m = t(as.matrix(m))
an = anno[anno$probe %in% rownames(m),]
an = an[an$gene %in% rownames(exp),]
an = an[an$location %in% c("TSS200","TSS1500"),]

p = apply(an,1,function(i){
  tryCatch(summary(lm(exp[as.character(i[2]),] ~ 
m[as.character(i[1]),]))$coefficient[2,4], error= function(e)NA)
})
t = apply(an,1,function(i){
  tryCatch(summary(lm(exp[as.character(i[2]),] ~ 
m[as.character(i[1]),]))$coefficient[2,3], error= function(e)NA)
})
an1 =cbind(an,p)
an1 = cbind(an1,t)
an1$q = p.adjust(as.numeric(an1$p))
summary(lm(exp["MAOB",] ~ m["cg00121904",]$coefficient[2,c(3:4)]
###

[[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] Finding the Mean of a Specific Set of Columns

2019-02-14 Thread Isaac Barnhart
I am having trouble finding the mean of a specific part of my dataset. Here is 
a sample of it:

plot lai leaf
1 104 82 1
2 104 167 2
3 104 248 3
4 104 343 4
5 104 377 5
6 105 64 1
7 105 139 2
8 105 211 3
9 105 296 4
10 105 348 5
11 106 94 1
12 106 167 2
13 106 243 3
14 106 281 4
15 106 332 5
16 108 83 1
17 108 382 2
18 108 320 3
19 108 146 4
20 108 129 5

I have many different plot numbers, none of which follow any kind of specific 
numeric sequence (even though I have sorted them from smallest to largest). I 
need to take the average (mean) of the LAI for each plot, and was wondering if 
there was a way to specify the code to do this. For example: I need the average 
of all the LAI measurements for each leaf of plot 104, 105, etc. Any help would 
be appreciated. Thanks!

Get Outlook for iOS

[[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] Finding the Mean of a Specific Set of Columns

2019-02-14 Thread Eric Berger
Hi Isaac,
I am sure you will get lots of answers to this. Here is one using the dplyr
package.
Assuming that your data frame is called 'a', then
library(dplyr)
b <- dplyr::group_by(a,plot) %>% dplyr::summarise( mean(lai) )
b
# A tibble: 4 x 2
   plot `mean(lai)`
 
1   104243.
2   105212.
3   106223.
4   108212

HTH,
Eric



On Thu, Feb 14, 2019 at 6:20 PM Isaac Barnhart  wrote:

> I am having trouble finding the mean of a specific part of my dataset.
> Here is a sample of it:
>
> plot lai leaf
> 1 104 82 1
> 2 104 167 2
> 3 104 248 3
> 4 104 343 4
> 5 104 377 5
> 6 105 64 1
> 7 105 139 2
> 8 105 211 3
> 9 105 296 4
> 10 105 348 5
> 11 106 94 1
> 12 106 167 2
> 13 106 243 3
> 14 106 281 4
> 15 106 332 5
> 16 108 83 1
> 17 108 382 2
> 18 108 320 3
> 19 108 146 4
> 20 108 129 5
>
> I have many different plot numbers, none of which follow any kind of
> specific numeric sequence (even though I have sorted them from smallest to
> largest). I need to take the average (mean) of the LAI for each plot, and
> was wondering if there was a way to specify the code to do this. For
> example: I need the average of all the LAI measurements for each leaf of
> plot 104, 105, etc. Any help would be appreciated. Thanks!
>
> Get Outlook for iOS
>
> [[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.


Re: [R] Finding the Mean of a Specific Set of Columns

2019-02-14 Thread Ben Tupper
Hi,

You might try your hand at the tidyverse collection of tools which are veddy 
nice for this kind of wrangling. https://www.tidyverse.org/

Does this do the trick?

## START
library(readr)
library(dplyr)

txt <- "row plot lai leaf
1 104 82 1
2 104 167 2
3 104 248 3
4 104 343 4
5 104 377 5
6 105 64 1
7 105 139 2
8 105 211 3
9 105 296 4
10 105 348 5
11 106 94 1
12 106 167 2
13 106 243 3
14 106 281 4
15 106 332 5
16 108 83 1
17 108 382 2
18 108 320 3
19 108 146 4
20 108 129 5"

x <- readr::read_delim(txt, delim = " ") %>%
dplyr::group_by(plot) %>%
dplyr::summarize(mean_lai = mean(lai))

x
# A tibble: 4 x 2
   # plot mean_lai
  # 
# 1   104 243.
# 2   105 212.
# 3   106 223.
# 4   108 212 

## END
 
Cheers,
Ben

>   [[alternative HTML version deleted]]


P.S.  Don't forget that HTML formatted emails get stripped of formatting on 
this list - so be sure to change your email client to send plain text.


> On Feb 14, 2019, at 9:31 AM, Isaac Barnhart  wrote:
> 
> I am having trouble finding the mean of a specific part of my dataset. Here 
> is a sample of it:
> 
> plot lai leaf
> 1 104 82 1
> 2 104 167 2
> 3 104 248 3
> 4 104 343 4
> 5 104 377 5
> 6 105 64 1
> 7 105 139 2
> 8 105 211 3
> 9 105 296 4
> 10 105 348 5
> 11 106 94 1
> 12 106 167 2
> 13 106 243 3
> 14 106 281 4
> 15 106 332 5
> 16 108 83 1
> 17 108 382 2
> 18 108 320 3
> 19 108 146 4
> 20 108 129 5
> 
> I have many different plot numbers, none of which follow any kind of specific 
> numeric sequence (even though I have sorted them from smallest to largest). I 
> need to take the average (mean) of the LAI for each plot, and was wondering 
> if there was a way to specify the code to do this. For example: I need the 
> average of all the LAI measurements for each leaf of plot 104, 105, etc. Any 
> help would be appreciated. Thanks!
> 
> Get Outlook for iOS
> 
>   [[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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/

__
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] Finding the Mean of a Specific Set of Columns

2019-02-14 Thread Marc Schwartz via R-help
On Feb 14, 2019, at 9:31 AM, Isaac Barnhart  wrote:
> 
> I am having trouble finding the mean of a specific part of my dataset. Here 
> is a sample of it:
> 
> plot lai leaf
> 1 104 82 1
> 2 104 167 2
> 3 104 248 3
> 4 104 343 4
> 5 104 377 5
> 6 105 64 1
> 7 105 139 2
> 8 105 211 3
> 9 105 296 4
> 10 105 348 5
> 11 106 94 1
> 12 106 167 2
> 13 106 243 3
> 14 106 281 4
> 15 106 332 5
> 16 108 83 1
> 17 108 382 2
> 18 108 320 3
> 19 108 146 4
> 20 108 129 5
> 
> I have many different plot numbers, none of which follow any kind of specific 
> numeric sequence (even though I have sorted them from smallest to largest). I 
> need to take the average (mean) of the LAI for each plot, and was wondering 
> if there was a way to specify the code to do this. For example: I need the 
> average of all the LAI measurements for each leaf of plot 104, 105, etc. Any 
> help would be appreciated. Thanks!


Hi, 

This is easy using base R functions. See ?aggregate, ?by and ?tapply for a 
starting place.

For example:

> aggregate(lai ~ plot, data = DF, FUN = mean)
  plot   lai
1  104 243.4
2  105 211.6
3  106 223.4
4  108 212.0

Regards,

Marc Schwartz

__
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] POSIXlt class and lapply

2019-02-14 Thread Newell, Paul
Dear R-helpers,

We have recently upgraded from R-3.3.1 to R-3.5.2.

It seems there has been a change in behaviour of `lapply` and the `POSIXlt` 
class that I cannot find explicitly documented.


In R-3.3.1:

> lapply(as.POSIXlt(Sys.Date()), length)
$sec
[1] 1
$min
[1] 1
$hour
[1] 1
$mday
[1] 1
$mon
[1] 1
$year
[1] 1
$wday
[1] 1
$yday
[1] 1
$isdst
[1] 1


whereas, in R-3.5.2:

> lapply(as.POSIXlt(Sys.Date()), length)
[[1]]
[1] 1


Is this change in behaviour intentional?

Realistically, I cannot see anything documented to say that `lapply` should 
behave as per R-3.3.1 on a `POSIXlt` object, so it is/was perhaps unwise to 
rely on it.


Best wishes,
Paul Newell
__
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] Finding the Mean of a Specific Set of Columns

2019-02-14 Thread Frederick Thielen
Hi,

try

library("dplyr")
plot <- c(104, 104 ,104 ,104 ,104 ,105 ,105 ,105 ,105 ,105,106,
  106,106,  106,  106,108,  108,108,108,108)

lai <- c(82, 167, 248, 343, 377, 64, 139, 211, 296, 348,
 94, 167,243,281,332,83, 382,320,146,129)

leaf <- c(1,2, 3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5)

df <- cbind(plot, lai, leaf) %>% data.frame()

df %>% dplyr::group_by(plot) %>% 
dplyr::summarise(mean = mean(lai, na.rm = T))


Best,
Frederick

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Isaac Barnhart
Sent: donderdag 14 februari 2019 15:32
To: r-help@r-project.org
Subject: [R] Finding the Mean of a Specific Set of Columns

I am having trouble finding the mean of a specific part of my dataset. Here is 
a sample of it:

plot lai leaf
1 104 82 1
2 104 167 2
3 104 248 3
4 104 343 4
5 104 377 5
6 105 64 1
7 105 139 2
8 105 211 3
9 105 296 4
10 105 348 5
11 106 94 1
12 106 167 2
13 106 243 3
14 106 281 4
15 106 332 5
16 108 83 1
17 108 382 2
18 108 320 3
19 108 146 4
20 108 129 5

I have many different plot numbers, none of which follow any kind of specific 
numeric sequence (even though I have sorted them from smallest to largest). I 
need to take the average (mean) of the LAI for each plot, and was wondering if 
there was a way to specify the code to do this. For example: I need the average 
of all the LAI measurements for each leaf of plot 104, 105, etc. Any help would 
be appreciated. Thanks!

Get Outlook for iOS

[[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.


Re: [R] POSIXlt class and lapply

2019-02-14 Thread William Dunlap via R-help
Somewhere between R-3.3.3 and R-3.5.2 a POSIXlt method for as.list() was
added, and lapply probably calls as.list().

> RCompare(methods("as.list"))
R version 3.3.3 (2017-03-06)| R version 3.5.1
(2018-07-02)
[1] as.list.data.frame  as.list.Date| [1]
as.list.data.frame  as.list.Date
[3] as.list.default as.list.environment | [3] as.list.default
   as.list.environment
[5] as.list.factor  as.list.function| [5] as.list.factor
  as.list.function
[7] as.list.numeric_version as.list.POSIXct | [7]
as.list.numeric_version as.list.POSIXct
see '?methods' for accessing help and source code   | [9] as.list.POSIXlt
| see '?methods' for
accessing help and source code


Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Thu, Feb 14, 2019 at 9:45 AM Newell, Paul 
wrote:

> Dear R-helpers,
>
> We have recently upgraded from R-3.3.1 to R-3.5.2.
>
> It seems there has been a change in behaviour of `lapply` and the
> `POSIXlt` class that I cannot find explicitly documented.
>
>
> In R-3.3.1:
>
> > lapply(as.POSIXlt(Sys.Date()), length)
> $sec
> [1] 1
> $min
> [1] 1
> $hour
> [1] 1
> $mday
> [1] 1
> $mon
> [1] 1
> $year
> [1] 1
> $wday
> [1] 1
> $yday
> [1] 1
> $isdst
> [1] 1
>
>
> whereas, in R-3.5.2:
>
> > lapply(as.POSIXlt(Sys.Date()), length)
> [[1]]
> [1] 1
>
>
> Is this change in behaviour intentional?
>
> Realistically, I cannot see anything documented to say that `lapply`
> should behave as per R-3.3.1 on a `POSIXlt` object, so it is/was perhaps
> unwise to rely on it.
>
>
> Best wishes,
> Paul Newell
> __
> 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] R help

2019-02-14 Thread Gouresh Kamble via R-help
Dear to whom it may concern on the R team, 



I am having an issue with creating a code in which i can hold information such 
as the author of a paper, the year of publication, and the title. Also would 
like to add into this data frame a logical variable which would show some 
keywords I used to find the data. I keep getting stuck on how to create 
specific characters for the table. 




Kind Regards, 
Gouresh Kamble 
__
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] Finding the Mean of a Specific Set of Columns

2019-02-14 Thread Isaac Barnhart
Thanks for the help!


Isaac




From: Marc Schwartz 
Sent: Thursday, February 14, 2019 11:05:23 AM
To: Isaac Barnhart
Cc: R-help
Subject: Re: [R] Finding the Mean of a Specific Set of Columns

On Feb 14, 2019, at 9:31 AM, Isaac Barnhart  wrote:
>
> I am having trouble finding the mean of a specific part of my dataset. Here 
> is a sample of it:
>
> plot lai leaf
> 1 104 82 1
> 2 104 167 2
> 3 104 248 3
> 4 104 343 4
> 5 104 377 5
> 6 105 64 1
> 7 105 139 2
> 8 105 211 3
> 9 105 296 4
> 10 105 348 5
> 11 106 94 1
> 12 106 167 2
> 13 106 243 3
> 14 106 281 4
> 15 106 332 5
> 16 108 83 1
> 17 108 382 2
> 18 108 320 3
> 19 108 146 4
> 20 108 129 5
>
> I have many different plot numbers, none of which follow any kind of specific 
> numeric sequence (even though I have sorted them from smallest to largest). I 
> need to take the average (mean) of the LAI for each plot, and was wondering 
> if there was a way to specify the code to do this. For example: I need the 
> average of all the LAI measurements for each leaf of plot 104, 105, etc. Any 
> help would be appreciated. Thanks!


Hi,

This is easy using base R functions. See ?aggregate, ?by and ?tapply for a 
starting place.

For example:

> aggregate(lai ~ plot, data = DF, FUN = mean)
  plot   lai
1  104 243.4
2  105 211.6
3  106 223.4
4  108 212.0

Regards,

Marc Schwartz




[[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] R help

2019-02-14 Thread Sarah Goslee
There's a bibtex parser for R: you could adapt that for your use,
rather than trying to reinvent the equivalent tool.

https://cran.r-project.org/web/packages/bibtex/index.html

Sarah

On Thu, Feb 14, 2019 at 5:57 PM Gouresh Kamble via R-help
 wrote:
>
> Dear to whom it may concern on the R team,
>
>
>
> I am having an issue with creating a code in which i can hold information 
> such as the author of a paper, the year of publication, and the title. Also 
> would like to add into this data frame a logical variable which would show 
> some keywords I used to find the data. I keep getting stuck on how to create 
> specific characters for the table.
>
>
>

-- 
Sarah Goslee (she/her)
http://www.numberwright.com

__
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] Extending my code

2019-02-14 Thread Ogbos Okike
Dear List,
I have a simple code with which I convert year, month, and day to a date format.
My data looks like:
67 01 2618464
67 01 2618472
67 01 2618408
67 01 2618360
67 01 2618328
67 01 2618320
67 01 2618296

while my code is:


data <- read.table("CALG.txt", col.names = c("year", "month", "day", "counts"))
 new.century <- data$year < 50
data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
data$date <- as.Date(ISOdate(data$year, data$month, data$day))
x = data$date
 y = data$counts

I now wish to extend this code to be able to include hour for another
data of the format:
05 01 01 004009
05 01 01 013969
05 01 01 023946
05 01 01 033975
05 01 01 043960
05 01 01 053974
05 01 01 063971
05 01 01 073970
That is, I now would like to include hour in:
data <- read.table("CALG.txt", col.names = c("year", "month", "day", "counts")).

I am aware there are many other way of conversion but I have a
specific interest here. This code is a preamble to a larger code and
changing it to another format other than what I have will not be
compatible with the general code. Or will rather be difficult for me
to get another format fit into my main code.

So if you would be kind enough to assist me to run the read.table in the format:

data <- read.table("CALG.txt", col.names = c("year", "month",
"day","hour", "counts"))

and then run the rest as:

new.century <- data$year < 50
data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
data$date <- as.Date(ISOdate(data$year, data$month, data$day,data$hour))
x = data$date

such that year, month, day and hour will be stored in x,

I will be very thankful.

Thank you so much for your kind assistance.
Best regards
Ogbos

__
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] Extending my code

2019-02-14 Thread Jeff Newmiller
The Date class is not designed to handle time... you need to use the 
ISOdatetime function and convert to POSIXct instead of Date. Just be sure to 
set your timezone to some appropriate value before you convert any times into 
datetime types.

Sys.setenv( TZ="GMT" )
# avoid using `data` as that is the name of a base R function
dta <- read.table("CALG.txt", col.names = c("year", "month", "day", "hour", 
"counts"))
dta$year <- with( dta, ifelse(year < 50, year + 2000, year + 1900)
dta$datetime <- with( dta, as.POSIXct(ISOdatetime(year, month,day,hour,0,0)))

I don't see why you feel obliged to copy the timestamp out of the data frame 
into x, but that is your business.

Appropriate timezone values can be reviewed with the OlsonNames() function. 


On February 14, 2019 10:29:58 PM PST, Ogbos Okike  
wrote:
>Dear List,
>I have a simple code with which I convert year, month, and day to a
>date format.
>My data looks like:
>67 01 2618464
>67 01 2618472
>67 01 2618408
>67 01 2618360
>67 01 2618328
>67 01 2618320
>67 01 2618296
>
>while my code is:
>
>
>data <- read.table("CALG.txt", col.names = c("year", "month", "day",
>"counts"))
> new.century <- data$year < 50
>data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
>data$date <- as.Date(ISOdate(data$year, data$month, data$day))
>x = data$date
> y = data$counts
>
>I now wish to extend this code to be able to include hour for another
>data of the format:
>05 01 01 004009
>05 01 01 013969
>05 01 01 023946
>05 01 01 033975
>05 01 01 043960
>05 01 01 053974
>05 01 01 063971
>05 01 01 073970
>That is, I now would like to include hour in:
>data <- read.table("CALG.txt", col.names = c("year", "month", "day",
>"counts")).
>
>I am aware there are many other way of conversion but I have a
>specific interest here. This code is a preamble to a larger code and
>changing it to another format other than what I have will not be
>compatible with the general code. Or will rather be difficult for me
>to get another format fit into my main code.
>
>So if you would be kind enough to assist me to run the read.table in
>the format:
>
>data <- read.table("CALG.txt", col.names = c("year", "month",
>"day","hour", "counts"))
>
>and then run the rest as:
>
>new.century <- data$year < 50
>data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
>data$date <- as.Date(ISOdate(data$year, data$month,
>data$day,data$hour))
>x = data$date
>
>such that year, month, day and hour will be stored in x,
>
>I will be very thankful.
>
>Thank you so much for your kind assistance.
>Best regards
>Ogbos
>
>__
>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.

-- 
Sent from my phone. Please excuse my brevity.

__
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] Extending my code

2019-02-14 Thread Ogbos Okike
Dear Jeff,

Thank you so much.

I ran the code but got an error message. I then try to  run them line by line.

The problem is in:
dta$datetime <- with( dta, as.POSIXct(ISOdatetime(year, month,day,hour,0,0)))
Error in with(dta, as.POSIXct(ISOdatetime(year, month, day, hour, 0, 0))) :
  object 'dta' not found

Thanks for another time.
Best
Ogbos

On Fri, Feb 15, 2019 at 7:51 AM Jeff Newmiller  wrote:
>
> The Date class is not designed to handle time... you need to use the 
> ISOdatetime function and convert to POSIXct instead of Date. Just be sure to 
> set your timezone to some appropriate value before you convert any times into 
> datetime types.
>
> Sys.setenv( TZ="GMT" )
> # avoid using `data` as that is the name of a base R function
> dta <- read.table("CALG.txt", col.names = c("year", "month", "day", "hour", 
> "counts"))
> dta$year <- with( dta, ifelse(year < 50, year + 2000, year + 1900)
> dta$datetime <- with( dta, as.POSIXct(ISOdatetime(year, month,day,hour,0,0)))
>
> I don't see why you feel obliged to copy the timestamp out of the data frame 
> into x, but that is your business.
>
> Appropriate timezone values can be reviewed with the OlsonNames() function.
>
>
> On February 14, 2019 10:29:58 PM PST, Ogbos Okike  
> wrote:
> >Dear List,
> >I have a simple code with which I convert year, month, and day to a
> >date format.
> >My data looks like:
> >67 01 2618464
> >67 01 2618472
> >67 01 2618408
> >67 01 2618360
> >67 01 2618328
> >67 01 2618320
> >67 01 2618296
> >
> >while my code is:
> >
> >
> >data <- read.table("CALG.txt", col.names = c("year", "month", "day",
> >"counts"))
> > new.century <- data$year < 50
> >data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
> >data$date <- as.Date(ISOdate(data$year, data$month, data$day))
> >x = data$date
> > y = data$counts
> >
> >I now wish to extend this code to be able to include hour for another
> >data of the format:
> >05 01 01 004009
> >05 01 01 013969
> >05 01 01 023946
> >05 01 01 033975
> >05 01 01 043960
> >05 01 01 053974
> >05 01 01 063971
> >05 01 01 073970
> >That is, I now would like to include hour in:
> >data <- read.table("CALG.txt", col.names = c("year", "month", "day",
> >"counts")).
> >
> >I am aware there are many other way of conversion but I have a
> >specific interest here. This code is a preamble to a larger code and
> >changing it to another format other than what I have will not be
> >compatible with the general code. Or will rather be difficult for me
> >to get another format fit into my main code.
> >
> >So if you would be kind enough to assist me to run the read.table in
> >the format:
> >
> >data <- read.table("CALG.txt", col.names = c("year", "month",
> >"day","hour", "counts"))
> >
> >and then run the rest as:
> >
> >new.century <- data$year < 50
> >data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
> >data$date <- as.Date(ISOdate(data$year, data$month,
> >data$day,data$hour))
> >x = data$date
> >
> >such that year, month, day and hour will be stored in x,
> >
> >I will be very thankful.
> >
> >Thank you so much for your kind assistance.
> >Best regards
> >Ogbos
> >
> >__
> >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.
>
> --
> Sent from my phone. Please excuse my brevity.

__
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] Extending my code

2019-02-14 Thread Ogbos Okike
Dear Jeff,

Please hold.
It is begging to work. There was an error somewhere. One ")" is
missing and as I went back to check the lines one by one with cursor,
I stubbed on non matching bracket.

I completed, run the code again and got some result.

Will get back to you once I am through.

Thanks in a hurry.
Best regards
Ogbos


On Fri, Feb 15, 2019 at 8:15 AM Ogbos Okike  wrote:
>
> Dear Jeff,
>
> Thank you so much.
>
> I ran the code but got an error message. I then try to  run them line by line.
>
> The problem is in:
> dta$datetime <- with( dta, as.POSIXct(ISOdatetime(year, month,day,hour,0,0)))
> Error in with(dta, as.POSIXct(ISOdatetime(year, month, day, hour, 0, 0))) :
>   object 'dta' not found
>
> Thanks for another time.
> Best
> Ogbos
>
> On Fri, Feb 15, 2019 at 7:51 AM Jeff Newmiller  
> wrote:
> >
> > The Date class is not designed to handle time... you need to use the 
> > ISOdatetime function and convert to POSIXct instead of Date. Just be sure 
> > to set your timezone to some appropriate value before you convert any times 
> > into datetime types.
> >
> > Sys.setenv( TZ="GMT" )
> > # avoid using `data` as that is the name of a base R function
> > dta <- read.table("CALG.txt", col.names = c("year", "month", "day", "hour", 
> > "counts"))
> > dta$year <- with( dta, ifelse(year < 50, year + 2000, year + 1900)
> > dta$datetime <- with( dta, as.POSIXct(ISOdatetime(year, 
> > month,day,hour,0,0)))
> >
> > I don't see why you feel obliged to copy the timestamp out of the data 
> > frame into x, but that is your business.
> >
> > Appropriate timezone values can be reviewed with the OlsonNames() function.
> >
> >
> > On February 14, 2019 10:29:58 PM PST, Ogbos Okike 
> >  wrote:
> > >Dear List,
> > >I have a simple code with which I convert year, month, and day to a
> > >date format.
> > >My data looks like:
> > >67 01 2618464
> > >67 01 2618472
> > >67 01 2618408
> > >67 01 2618360
> > >67 01 2618328
> > >67 01 2618320
> > >67 01 2618296
> > >
> > >while my code is:
> > >
> > >
> > >data <- read.table("CALG.txt", col.names = c("year", "month", "day",
> > >"counts"))
> > > new.century <- data$year < 50
> > >data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
> > >data$date <- as.Date(ISOdate(data$year, data$month, data$day))
> > >x = data$date
> > > y = data$counts
> > >
> > >I now wish to extend this code to be able to include hour for another
> > >data of the format:
> > >05 01 01 004009
> > >05 01 01 013969
> > >05 01 01 023946
> > >05 01 01 033975
> > >05 01 01 043960
> > >05 01 01 053974
> > >05 01 01 063971
> > >05 01 01 073970
> > >That is, I now would like to include hour in:
> > >data <- read.table("CALG.txt", col.names = c("year", "month", "day",
> > >"counts")).
> > >
> > >I am aware there are many other way of conversion but I have a
> > >specific interest here. This code is a preamble to a larger code and
> > >changing it to another format other than what I have will not be
> > >compatible with the general code. Or will rather be difficult for me
> > >to get another format fit into my main code.
> > >
> > >So if you would be kind enough to assist me to run the read.table in
> > >the format:
> > >
> > >data <- read.table("CALG.txt", col.names = c("year", "month",
> > >"day","hour", "counts"))
> > >
> > >and then run the rest as:
> > >
> > >new.century <- data$year < 50
> > >data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
> > >data$date <- as.Date(ISOdate(data$year, data$month,
> > >data$day,data$hour))
> > >x = data$date
> > >
> > >such that year, month, day and hour will be stored in x,
> > >
> > >I will be very thankful.
> > >
> > >Thank you so much for your kind assistance.
> > >Best regards
> > >Ogbos
> > >
> > >__
> > >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.
> >
> > --
> > Sent from my phone. Please excuse my brevity.

__
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] Extending my code: SOLVED

2019-02-14 Thread Ogbos Okike
Dear Jeff,
I am alright now

Please accept my indebtedness!!!

Warmest regards
Ogbos
On Fri, Feb 15, 2019 at 8:25 AM Ogbos Okike  wrote:
>
> Dear Jeff,
>
> Please hold.
> It is begging to work. There was an error somewhere. One ")" is
> missing and as I went back to check the lines one by one with cursor,
> I stubbed on non matching bracket.
>
> I completed, run the code again and got some result.
>
> Will get back to you once I am through.
>
> Thanks in a hurry.
> Best regards
> Ogbos
>
>
> On Fri, Feb 15, 2019 at 8:15 AM Ogbos Okike  wrote:
> >
> > Dear Jeff,
> >
> > Thank you so much.
> >
> > I ran the code but got an error message. I then try to  run them line by 
> > line.
> >
> > The problem is in:
> > dta$datetime <- with( dta, as.POSIXct(ISOdatetime(year, 
> > month,day,hour,0,0)))
> > Error in with(dta, as.POSIXct(ISOdatetime(year, month, day, hour, 0, 0))) :
> >   object 'dta' not found
> >
> > Thanks for another time.
> > Best
> > Ogbos
> >
> > On Fri, Feb 15, 2019 at 7:51 AM Jeff Newmiller  
> > wrote:
> > >
> > > The Date class is not designed to handle time... you need to use the 
> > > ISOdatetime function and convert to POSIXct instead of Date. Just be sure 
> > > to set your timezone to some appropriate value before you convert any 
> > > times into datetime types.
> > >
> > > Sys.setenv( TZ="GMT" )
> > > # avoid using `data` as that is the name of a base R function
> > > dta <- read.table("CALG.txt", col.names = c("year", "month", "day", 
> > > "hour", "counts"))
> > > dta$year <- with( dta, ifelse(year < 50, year + 2000, year + 1900)
> > > dta$datetime <- with( dta, as.POSIXct(ISOdatetime(year, 
> > > month,day,hour,0,0)))
> > >
> > > I don't see why you feel obliged to copy the timestamp out of the data 
> > > frame into x, but that is your business.
> > >
> > > Appropriate timezone values can be reviewed with the OlsonNames() 
> > > function.
> > >
> > >
> > > On February 14, 2019 10:29:58 PM PST, Ogbos Okike 
> > >  wrote:
> > > >Dear List,
> > > >I have a simple code with which I convert year, month, and day to a
> > > >date format.
> > > >My data looks like:
> > > >67 01 2618464
> > > >67 01 2618472
> > > >67 01 2618408
> > > >67 01 2618360
> > > >67 01 2618328
> > > >67 01 2618320
> > > >67 01 2618296
> > > >
> > > >while my code is:
> > > >
> > > >
> > > >data <- read.table("CALG.txt", col.names = c("year", "month", "day",
> > > >"counts"))
> > > > new.century <- data$year < 50
> > > >data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
> > > >data$date <- as.Date(ISOdate(data$year, data$month, data$day))
> > > >x = data$date
> > > > y = data$counts
> > > >
> > > >I now wish to extend this code to be able to include hour for another
> > > >data of the format:
> > > >05 01 01 004009
> > > >05 01 01 013969
> > > >05 01 01 023946
> > > >05 01 01 033975
> > > >05 01 01 043960
> > > >05 01 01 053974
> > > >05 01 01 063971
> > > >05 01 01 073970
> > > >That is, I now would like to include hour in:
> > > >data <- read.table("CALG.txt", col.names = c("year", "month", "day",
> > > >"counts")).
> > > >
> > > >I am aware there are many other way of conversion but I have a
> > > >specific interest here. This code is a preamble to a larger code and
> > > >changing it to another format other than what I have will not be
> > > >compatible with the general code. Or will rather be difficult for me
> > > >to get another format fit into my main code.
> > > >
> > > >So if you would be kind enough to assist me to run the read.table in
> > > >the format:
> > > >
> > > >data <- read.table("CALG.txt", col.names = c("year", "month",
> > > >"day","hour", "counts"))
> > > >
> > > >and then run the rest as:
> > > >
> > > >new.century <- data$year < 50
> > > >data$year <- ifelse(new.century, data$year + 2000, data$year + 1900)
> > > >data$date <- as.Date(ISOdate(data$year, data$month,
> > > >data$day,data$hour))
> > > >x = data$date
> > > >
> > > >such that year, month, day and hour will be stored in x,
> > > >
> > > >I will be very thankful.
> > > >
> > > >Thank you so much for your kind assistance.
> > > >Best regards
> > > >Ogbos
> > > >
> > > >__
> > > >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.
> > >
> > > --
> > > Sent from my phone. Please excuse my brevity.

__
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.