Re: [R] Help with r script

2018-09-05 Thread ruipbarradas
Hello,
25*30 
This is the most basic possible, please google an intro text and run its 
examples.
Hope this helps,
Rui Barradas 


Enviado a partir do meu smartphone Samsung Galaxy. Mensagem original 
De: Nathan D Jennings  Data: 05/09/2018  
00:30  (GMT+00:00) Para: r-help@r-project.org Assunto: [R] Help with r script 
 To the R Project:

I am using R Studio and I need help sum product exponents with R Script.  Every 
time I type at the very start in the R Script window like 25* 30 nothing 
happens.  Where can I go to find the complete commands for basic functions in 
the r script window?


Sincerely,


Nathan Jennings

[[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] Help with r script

2018-09-04 Thread Jeff Newmiller

On Tue, 4 Sep 2018, Nathan D Jennings wrote:


?To the R Project:


This is the R-help mailing list, populated by various people who use R 
including the occasional R-core developer.



I am using R Studio and I need help sum product exponents with R Script.


a) This is the R-help mailing list, not the RStudio-help mailing list. 
RStudio is only one of numerous user interfaces that can be used to 
interact with R. This mailing list is about the language, not the user 
interface. They do have a forum [1].


 Every time I type at the very start in the R Script window like 25* 30 
nothing happens.


b) I think the window you are describing as the "R Script" window is 
actually a text editor window. All interaction with R occurs in the R 
Console, and the text editor window is a place to keep organized in a file 
the commands you write that seem to do what you want when executed in the 
Console. Usually you will need a number of commands executed in sequence 
to accomplish whatever analysis goal you have, so a text file is a good 
place to keep those commands organized. You can position the cursor on an 
R command in the editor and hold down the control key and press Enter, and 
RStudio will type it into the console window for you. Once you are 
confident those commands work you can use the source() function to have R 
execute the entire file of commands at once. You would look for the 
response/result/output in the Console and/or the Plot windows depending 
which commands you used.


 Where can I go to find the complete commands for basic functions in the 
r script window?


c) I don't think that there is any comprehensive list of commands you can 
give to R. There are many introductory R books, and there is an 
Introduction to R document provided with R [2]. You might find the 
cheatsheets listed under the Help/Cheatsheets menu in RStudio helpful to 
give you some clues. If you want a thorough discussion of the structure of 
the R language you can refer to the R Language Definition [3], but that is 
really rather dense going if you are just starting out... an introductory 
book or the r-intro document would probably be most useful to you at this 
point.


Finally, per the Posting Guide mentioned below this mailing list is not 
appropriate for students doing homework... from your email address I think 
you should have local resources who can boost you up the learning curve 
much more efficiently than we can through a plain text mailing list (or 
even the RStudio forum). In this mailing list, you need to understand 
enough R to be able to post R code that illustrates what isn't working for 
you, along with a clear specification of what you wanted to get.


[1] https://community.rstudio.com/
[2] https://cran.r-project.org/doc/manuals/r-release/R-intro.pdf
[3] https://cran.r-project.org/manuals.html

---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
__
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 r script

2018-09-04 Thread Nathan D Jennings
 To the R Project:

I am using R Studio and I need help sum product exponents with R Script.  Every 
time I type at the very start in the R Script window like 25* 30 nothing 
happens.  Where can I go to find the complete commands for basic functions in 
the r script window?


Sincerely,


Nathan Jennings

[[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 with R script

2017-07-14 Thread Vijayan Padmanabhan
Thanks Ulrik and MacQueen
I am taking inputs from both your options to
arrive at the solution that will work for my
specific requirements..
Will post my final solution once I succeed..which
could help others with similar challenge in their
work..
Appreciate both your time shared on suggesting
these solutions..

Thanks & Regards
VP




From:   Ulrik Stervbo
<ulrik.ster...@gmail.com>
To: "MacQueen, Don" <macque...@llnl.gov>,
Vijayan Padmanabhan
<v.padmanab...@itc.in>,
"r-help@r-project.org"
<r-help@r-project.org>
Date:   14-07-2017 10:39
Subject:Re: [R] Help with R script



@Don your solution does not solve Vijayan's
scenario 2. I used spread and gather for that.

An alternative solution to insert mising Fval -
picking up with Don's newtst - is

newtst <- c("FName: fname1", "Fval: Fval1.name1",
"FName: fname2", "Fval: Fval2.name2", "FName:
fname3", "FName: fname4", "Fval: fval4.fname4")

newtst_new <- vector(mode = "character", length =
sum(grepl("FName", newtst)) * 2)
newtst_len <- length(newtst)
i <- 1
j <- 1
while(i <= newtst_len){
  if(grepl("FName", newtst[i]) & grepl("Fval",
newtst[i + 1])){
    newtst_new[c(j, j + 1)] <- newtst[c(i, i + 1)]
    i <- i + 2
  }else{
    newtst_new[c(j, j + 1)] <- c(newtst[c(i)],
"Fval: ")
    i <- i + 1
  }
  j <- j + 2

}
newtst_new

which is also not very pretty.

HTH
Ulrik

On Thu, 13 Jul 2017 at 16:48 MacQueen, Don <
macque...@llnl.gov> wrote:
  Using Ulrik’s example data (and assuming I
  understand what is wanted), here is what I would
  do:

  ex.dat <- c("FName: fname1", "Fval:
  Fval1.name1", "Fval: ", "FName: fname2", "Fval:
  Fval2.name2", "FName: fname3")
  tst <- data.frame(x = ex.dat,
  stringsAsFactors=FALSE)

  sp <- strsplit(tst$x, ':', fixed=TRUE)
  chk <- unlist(lapply(sp, function(txt) txt[2] !=
  ' '))
  newtst <- tst[chk,,drop=FALSE]

  This both assumes and requires that ALL of the
  rows are structured as in the example data in
  the original question.
  For example:
    if any row is missing the “:”, it will fail.
    If the “:” is not followed by a space
  character it may fail (I have not checked)

  -Don

  --
  Don MacQueen

  Lawrence Livermore National Laboratory
  7000 East Ave., L-627
  Livermore, CA 94550
  925-423-1062


  On 7/13/17, 6:47 AM, "R-help on behalf of Ulrik
  Stervbo" <r-help-boun...@r-project.org on behalf
  of ulrik.ster...@gmail.com> wrote:

      Hi Vijayan,

      one way going about it *could* be this:

      library(dplyr)
      library(tidyr)
      library(purrr)

      ex_dat <- c("FName: fname1", "Fval:
  Fval1.name1", "Fval: ", "FName:
      fname2", "Fval: Fval2.name2", "FName:
  fname3")

      data.frame(x = ex_dat) %>%
        separate(x, c("F1", "F2"), sep = ": ") %>%
        filter(F2 != "") %>%
        group_by(F1) %>%
        mutate(indx = row_number()) %>%
        spread(F1, F2, fill = "") %>%
        gather(F1, F2, FName, Fval) %>%
        arrange(indx) %>%
        mutate(x = paste(F1, F2, sep = ": ")) %>%
        select(x) %>%
        flatten_chr()

      It is not particularly nice or clever, but
  it gets the job done using R.

      HTH
      Ulrik

      On Thu, 13 Jul 2017 at 13:13 Vijayan
  Padmanabhan <v.padmanab...@itc.in>
      wrote:

      >
      > Dear R-help Group
      >
      >
      > Scenario 1:
      > I have a text file running to 1000 of
  lines...that
      > is like as follows:
      >
      > [922] "FieldName: Wk3PackSubMonth"
      >
      >  [923] "FieldValue: Apr"
      >
      >  [924] "FieldName: Wk3PackSubYear"
      >
      >  [925] "FieldValue: 2017"
      >
      >  [926] "FieldName: Wk3Code1"
      >
      >  [927] "FieldValue: "
      >
      >  [928] "FieldValue: K4"
      >
      >  [929] "FieldName: Wk3Code2"
      >
      >  [930] "FieldValue: "
      >
      >  [931] "FieldValue: Q49"
      >
      >
      > I want this to be programmatically
  corrected to
      > read as follows: (All consecutive lines
  starting
      > with FieldValue is cleaned to retain only
  one
      > line)
      >
      > [922] "FieldName: Wk3PackSubMonth"
      >
      >  [923] "FieldValue: Apr"
      >
      >  [924] "FieldName: Wk3PackSubYear"
      >
      >  [925] "FieldValue: 2017"

Re: [R] Help with R script

2017-07-13 Thread Ulrik Stervbo
@Don your solution does not solve Vijayan's scenario 2. I used spread and
gather for that.

An alternative solution to insert mising Fval - picking up with Don's
newtst - is

newtst <- c("FName: fname1", "Fval: Fval1.name1", "FName: fname2", "Fval:
Fval2.name2", "FName: fname3", "FName: fname4", "Fval: fval4.fname4")

newtst_new <- vector(mode = "character", length = sum(grepl("FName",
newtst)) * 2)
newtst_len <- length(newtst)
i <- 1
j <- 1
while(i <= newtst_len){
  if(grepl("FName", newtst[i]) & grepl("Fval", newtst[i + 1])){
newtst_new[c(j, j + 1)] <- newtst[c(i, i + 1)]
i <- i + 2
  }else{
newtst_new[c(j, j + 1)] <- c(newtst[c(i)], "Fval: ")
i <- i + 1
  }
  j <- j + 2

}
newtst_new

which is also not very pretty.

HTH
Ulrik

On Thu, 13 Jul 2017 at 16:48 MacQueen, Don  wrote:

> Using Ulrik’s example data (and assuming I understand what is wanted),
> here is what I would do:
>
> ex.dat <- c("FName: fname1", "Fval: Fval1.name1", "Fval: ", "FName:
> fname2", "Fval: Fval2.name2", "FName: fname3")
> tst <- data.frame(x = ex.dat, stringsAsFactors=FALSE)
>
> sp <- strsplit(tst$x, ':', fixed=TRUE)
> chk <- unlist(lapply(sp, function(txt) txt[2] != ' '))
> newtst <- tst[chk,,drop=FALSE]
>
> This both assumes and requires that ALL of the rows are structured as in
> the example data in the original question.
> For example:
>   if any row is missing the “:”, it will fail.
>   If the “:” is not followed by a space character it may fail (I have not
> checked)
>
> -Don
>
> --
> Don MacQueen
>
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
>
>
> On 7/13/17, 6:47 AM, "R-help on behalf of Ulrik Stervbo" <
> r-help-boun...@r-project.org on behalf of ulrik.ster...@gmail.com> wrote:
>
> Hi Vijayan,
>
> one way going about it *could* be this:
>
> library(dplyr)
> library(tidyr)
> library(purrr)
>
> ex_dat <- c("FName: fname1", "Fval: Fval1.name1", "Fval: ", "FName:
> fname2", "Fval: Fval2.name2", "FName: fname3")
>
> data.frame(x = ex_dat) %>%
>   separate(x, c("F1", "F2"), sep = ": ") %>%
>   filter(F2 != "") %>%
>   group_by(F1) %>%
>   mutate(indx = row_number()) %>%
>   spread(F1, F2, fill = "") %>%
>   gather(F1, F2, FName, Fval) %>%
>   arrange(indx) %>%
>   mutate(x = paste(F1, F2, sep = ": ")) %>%
>   select(x) %>%
>   flatten_chr()
>
> It is not particularly nice or clever, but it gets the job done using
> R.
>
> HTH
> Ulrik
>
> On Thu, 13 Jul 2017 at 13:13 Vijayan Padmanabhan  >
> wrote:
>
> >
> > Dear R-help Group
> >
> >
> > Scenario 1:
> > I have a text file running to 1000 of lines...that
> > is like as follows:
> >
> > [922] "FieldName: Wk3PackSubMonth"
> >
> >  [923] "FieldValue: Apr"
> >
> >  [924] "FieldName: Wk3PackSubYear"
> >
> >  [925] "FieldValue: 2017"
> >
> >  [926] "FieldName: Wk3Code1"
> >
> >  [927] "FieldValue: "
> >
> >  [928] "FieldValue: K4"
> >
> >  [929] "FieldName: Wk3Code2"
> >
> >  [930] "FieldValue: "
> >
> >  [931] "FieldValue: Q49"
> >
> >
> > I want this to be programmatically corrected to
> > read as follows: (All consecutive lines starting
> > with FieldValue is cleaned to retain only one
> > line)
> >
> > [922] "FieldName: Wk3PackSubMonth"
> >
> >  [923] "FieldValue: Apr"
> >
> >  [924] "FieldName: Wk3PackSubYear"
> >
> >  [925] "FieldValue: 2017"
> >
> >  [926] "FieldName: Wk3Code1"
> >
> >  [927] "FieldValue: K4"
> >
> >  [928] "FieldName: Wk3Code2"
> >
> >  [929] "FieldValue: Q49"
> >
> > Scenario 2:
> > In the same file, in some instances, the lines
> > could be as follows: in this case, wherever a line
> > is beginning with FieldName and the subsequent
> > line is not displaying a FieldValue, I would want
> > to programmatically identify such lines and insert
> > FieldValue (as blank).
> >
> > [941] "FieldName: Wk3Code6"
> >
> >  [942] "FieldValue: "
> >
> >  [943] "FieldName: Wk3Code7"
> >
> >  [944] "FieldValue: "
> >
> >  [945] "FieldName: Wk3PackWSColorStiffRemarkCode1"
> >
> >  [946] "FieldName: Wk3PackWSColorWrappRemarkCode1"
> >
> >  [947] "FieldName:
> > Wk3PackWSDelamiStiffRemarkCode1"
> >
> >
> > ie in the above, it should be replaced as
> >
> > [941] "FieldName: Wk3Code6"
> >
> >  [942] "FieldValue: "
> >
> >  [943] "FieldName: Wk3Code7"
> >
> >  [944] "FieldValue: "
> >
> >  [945] "FieldName: Wk3PackWSColorStiffRemarkCode1"
> >  [946] "FieldValue: "
> >
> >  [947] "FieldName: Wk3PackWSColorWrappRemarkCode1"
> >  [948] "FieldValue: "
> >
> >  [949] "FieldName:
> > Wk3PackWSDelamiStiffRemarkCode1"
>   

Re: [R] Help with R script

2017-07-13 Thread MacQueen, Don
Using Ulrik’s example data (and assuming I understand what is wanted), here is 
what I would do:

ex.dat <- c("FName: fname1", "Fval: Fval1.name1", "Fval: ", "FName: fname2", 
"Fval: Fval2.name2", "FName: fname3")
tst <- data.frame(x = ex.dat, stringsAsFactors=FALSE)

sp <- strsplit(tst$x, ':', fixed=TRUE)
chk <- unlist(lapply(sp, function(txt) txt[2] != ' '))
newtst <- tst[chk,,drop=FALSE]

This both assumes and requires that ALL of the rows are structured as in the 
example data in the original question.
For example:
  if any row is missing the “:”, it will fail.
  If the “:” is not followed by a space character it may fail (I have not 
checked)

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062


On 7/13/17, 6:47 AM, "R-help on behalf of Ulrik Stervbo" 
 wrote:

Hi Vijayan,

one way going about it *could* be this:

library(dplyr)
library(tidyr)
library(purrr)

ex_dat <- c("FName: fname1", "Fval: Fval1.name1", "Fval: ", "FName:
fname2", "Fval: Fval2.name2", "FName: fname3")

data.frame(x = ex_dat) %>%
  separate(x, c("F1", "F2"), sep = ": ") %>%
  filter(F2 != "") %>%
  group_by(F1) %>%
  mutate(indx = row_number()) %>%
  spread(F1, F2, fill = "") %>%
  gather(F1, F2, FName, Fval) %>%
  arrange(indx) %>%
  mutate(x = paste(F1, F2, sep = ": ")) %>%
  select(x) %>%
  flatten_chr()

It is not particularly nice or clever, but it gets the job done using R.

HTH
Ulrik

On Thu, 13 Jul 2017 at 13:13 Vijayan Padmanabhan 
wrote:

>
> Dear R-help Group
>
>
> Scenario 1:
> I have a text file running to 1000 of lines...that
> is like as follows:
>
> [922] "FieldName: Wk3PackSubMonth"
>
>  [923] "FieldValue: Apr"
>
>  [924] "FieldName: Wk3PackSubYear"
>
>  [925] "FieldValue: 2017"
>
>  [926] "FieldName: Wk3Code1"
>
>  [927] "FieldValue: "
>
>  [928] "FieldValue: K4"
>
>  [929] "FieldName: Wk3Code2"
>
>  [930] "FieldValue: "
>
>  [931] "FieldValue: Q49"
>
>
> I want this to be programmatically corrected to
> read as follows: (All consecutive lines starting
> with FieldValue is cleaned to retain only one
> line)
>
> [922] "FieldName: Wk3PackSubMonth"
>
>  [923] "FieldValue: Apr"
>
>  [924] "FieldName: Wk3PackSubYear"
>
>  [925] "FieldValue: 2017"
>
>  [926] "FieldName: Wk3Code1"
>
>  [927] "FieldValue: K4"
>
>  [928] "FieldName: Wk3Code2"
>
>  [929] "FieldValue: Q49"
>
> Scenario 2:
> In the same file, in some instances, the lines
> could be as follows: in this case, wherever a line
> is beginning with FieldName and the subsequent
> line is not displaying a FieldValue, I would want
> to programmatically identify such lines and insert
> FieldValue (as blank).
>
> [941] "FieldName: Wk3Code6"
>
>  [942] "FieldValue: "
>
>  [943] "FieldName: Wk3Code7"
>
>  [944] "FieldValue: "
>
>  [945] "FieldName: Wk3PackWSColorStiffRemarkCode1"
>
>  [946] "FieldName: Wk3PackWSColorWrappRemarkCode1"
>
>  [947] "FieldName:
> Wk3PackWSDelamiStiffRemarkCode1"
>
>
> ie in the above, it should be replaced as
>
> [941] "FieldName: Wk3Code6"
>
>  [942] "FieldValue: "
>
>  [943] "FieldName: Wk3Code7"
>
>  [944] "FieldValue: "
>
>  [945] "FieldName: Wk3PackWSColorStiffRemarkCode1"
>  [946] "FieldValue: "
>
>  [947] "FieldName: Wk3PackWSColorWrappRemarkCode1"
>  [948] "FieldValue: "
>
>  [949] "FieldName:
> Wk3PackWSDelamiStiffRemarkCode1"
>  [950] "FieldValue: "
>
>
> Can anybod suggest how to acheive this in R?
>
> Thanks for your time.
> Regards
> VP
>
>
>
> Disclaimer:\ This Communication is for the exclusive use...{{dropped:8}}
>
> __
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see

Re: [R] Help with R script

2017-07-13 Thread Ulrik Stervbo
Hi Vijayan,

one way going about it *could* be this:

library(dplyr)
library(tidyr)
library(purrr)

ex_dat <- c("FName: fname1", "Fval: Fval1.name1", "Fval: ", "FName:
fname2", "Fval: Fval2.name2", "FName: fname3")

data.frame(x = ex_dat) %>%
  separate(x, c("F1", "F2"), sep = ": ") %>%
  filter(F2 != "") %>%
  group_by(F1) %>%
  mutate(indx = row_number()) %>%
  spread(F1, F2, fill = "") %>%
  gather(F1, F2, FName, Fval) %>%
  arrange(indx) %>%
  mutate(x = paste(F1, F2, sep = ": ")) %>%
  select(x) %>%
  flatten_chr()

It is not particularly nice or clever, but it gets the job done using R.

HTH
Ulrik

On Thu, 13 Jul 2017 at 13:13 Vijayan Padmanabhan 
wrote:

>
> Dear R-help Group
>
>
> Scenario 1:
> I have a text file running to 1000 of lines...that
> is like as follows:
>
> [922] "FieldName: Wk3PackSubMonth"
>
>  [923] "FieldValue: Apr"
>
>  [924] "FieldName: Wk3PackSubYear"
>
>  [925] "FieldValue: 2017"
>
>  [926] "FieldName: Wk3Code1"
>
>  [927] "FieldValue: "
>
>  [928] "FieldValue: K4"
>
>  [929] "FieldName: Wk3Code2"
>
>  [930] "FieldValue: "
>
>  [931] "FieldValue: Q49"
>
>
> I want this to be programmatically corrected to
> read as follows: (All consecutive lines starting
> with FieldValue is cleaned to retain only one
> line)
>
> [922] "FieldName: Wk3PackSubMonth"
>
>  [923] "FieldValue: Apr"
>
>  [924] "FieldName: Wk3PackSubYear"
>
>  [925] "FieldValue: 2017"
>
>  [926] "FieldName: Wk3Code1"
>
>  [927] "FieldValue: K4"
>
>  [928] "FieldName: Wk3Code2"
>
>  [929] "FieldValue: Q49"
>
> Scenario 2:
> In the same file, in some instances, the lines
> could be as follows: in this case, wherever a line
> is beginning with FieldName and the subsequent
> line is not displaying a FieldValue, I would want
> to programmatically identify such lines and insert
> FieldValue (as blank).
>
> [941] "FieldName: Wk3Code6"
>
>  [942] "FieldValue: "
>
>  [943] "FieldName: Wk3Code7"
>
>  [944] "FieldValue: "
>
>  [945] "FieldName: Wk3PackWSColorStiffRemarkCode1"
>
>  [946] "FieldName: Wk3PackWSColorWrappRemarkCode1"
>
>  [947] "FieldName:
> Wk3PackWSDelamiStiffRemarkCode1"
>
>
> ie in the above, it should be replaced as
>
> [941] "FieldName: Wk3Code6"
>
>  [942] "FieldValue: "
>
>  [943] "FieldName: Wk3Code7"
>
>  [944] "FieldValue: "
>
>  [945] "FieldName: Wk3PackWSColorStiffRemarkCode1"
>  [946] "FieldValue: "
>
>  [947] "FieldName: Wk3PackWSColorWrappRemarkCode1"
>  [948] "FieldValue: "
>
>  [949] "FieldName:
> Wk3PackWSDelamiStiffRemarkCode1"
>  [950] "FieldValue: "
>
>
> Can anybod suggest how to acheive this in R?
>
> Thanks for your time.
> Regards
> VP
>
>
>
> Disclaimer:\ This Communication is for the exclusive use...{{dropped:8}}
>
> __
> 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 with R script

2017-07-13 Thread Vijayan Padmanabhan

Dear R-help Group


Scenario 1:
I have a text file running to 1000 of lines...that
is like as follows:

[922] "FieldName: Wk3PackSubMonth"

 [923] "FieldValue: Apr"

 [924] "FieldName: Wk3PackSubYear"

 [925] "FieldValue: 2017"

 [926] "FieldName: Wk3Code1"

 [927] "FieldValue: "

 [928] "FieldValue: K4"

 [929] "FieldName: Wk3Code2"

 [930] "FieldValue: "

 [931] "FieldValue: Q49"


I want this to be programmatically corrected to
read as follows: (All consecutive lines starting
with FieldValue is cleaned to retain only one
line)

[922] "FieldName: Wk3PackSubMonth"

 [923] "FieldValue: Apr"

 [924] "FieldName: Wk3PackSubYear"

 [925] "FieldValue: 2017"

 [926] "FieldName: Wk3Code1"

 [927] "FieldValue: K4"

 [928] "FieldName: Wk3Code2"

 [929] "FieldValue: Q49"

Scenario 2:
In the same file, in some instances, the lines
could be as follows: in this case, wherever a line
is beginning with FieldName and the subsequent
line is not displaying a FieldValue, I would want
to programmatically identify such lines and insert
FieldValue (as blank).

[941] "FieldName: Wk3Code6"

 [942] "FieldValue: "

 [943] "FieldName: Wk3Code7"

 [944] "FieldValue: "

 [945] "FieldName: Wk3PackWSColorStiffRemarkCode1"

 [946] "FieldName: Wk3PackWSColorWrappRemarkCode1"

 [947] "FieldName:
Wk3PackWSDelamiStiffRemarkCode1"


ie in the above, it should be replaced as

[941] "FieldName: Wk3Code6"

 [942] "FieldValue: "

 [943] "FieldName: Wk3Code7"

 [944] "FieldValue: "

 [945] "FieldName: Wk3PackWSColorStiffRemarkCode1"
 [946] "FieldValue: "

 [947] "FieldName: Wk3PackWSColorWrappRemarkCode1"
 [948] "FieldValue: "

 [949] "FieldName:
Wk3PackWSDelamiStiffRemarkCode1"
 [950] "FieldValue: "


Can anybod suggest how to acheive this in R?

Thanks for your time.
Regards
VP



Disclaimer:\ This Communication is for the exclusive use...{{dropped:8}}

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