[R] 1st script
PIKAL Petr
petr.pikal at precheza.cz
Mon Mar 23 06:58:52 CET 2015
Hi
use list and numeric indexing. As you did not provide reproducibe example here is possible way.
dat <- data.frame(w=abs(rnorm(10)), LC09=round(runif(10)*10), LC10=round(runif(10)*10))
lll <- vector("list", 2)
k=0
for(i in 2:3) {
k=k+1
lll[[k]] <- rep(dat$w, dat[,i])
}
names(lll)<-names(dat[,2:3])
boxplot(lll)
Cheers
Petr
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of
> memilanuk
> Sent: Monday, March 23, 2015 2:22 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] 1st script
>
> So... wrote my first script, rather than just using the interactive
> console. I think I got everything working more or less the way I want,
> but I'm sure there's a ton of room for improvement. Specifically in
> the
> way of automation - but thats where I kind of ran out of steam. Any
> suggestions would be much appreciated.
>
> case_data.r
>
> # Import CSV file into a data frame.
> case_weights <- read.csv(file = "case_weights.csv")
>
> # For each row, take the number in the Weight column and replicate it
> # as many times as there are in each count column.
> LC09 <- rep(case_weights$Weight, case_weights$LC09)
> LC10 <- rep(case_weights$Weight, case_weights$LC10)
> LP14b1 <- rep(case_weights$Weight, case_weights$LP14b1)
> LP14b2 <- rep(case_weights$Weight, case_weights$LP14b2)
>
> # Determine the longest vector, to help with the next step.
> max.len <- max(length(LC09), length(LC10), length(LP14b1),
> length(LP14b2))
>
> # Pad each vector with NA so they are all the same length and will
> # go in a data frame.
> LC09 <- c(LC09, rep(NA, max.len - length(LC09)))
> LC10 <- c(LC10, rep(NA, max.len - length(LC10)))
> LP14b1 <- c(LP14b1, rep(NA, max.len - length(LP14b1)))
> LP14b2 <- c(LP14b2, rep(NA, max.len - length(LP14b2)))
>
> # Stick everything back into one data frame.
> case_dat <- data.frame(LC09)
> case_dat$LC10 <- LC10
> case_dat$LP14b1 <- LP14b1
> case_dat$LP14b2 <- LP14b2
>
> # Stuff said data frame back into a CSV for use elsewhere (plot.ly).
> write.csv(case_dat, file = "expanded_case_weights.csv")
>
> # Boxplot it
> boxplot(case_dat, varwidth = TRUE, notch = TRUE, horizontal = TRUE,
> main = "Case Weights", xlab = "Weight (grains)",
> ylab = "Batch", las = 1, names = c("LC09", "LC10", "LP14b1",
> "LP14b2"))
>
>
>
> --
> Shiny! Let's be bad guys.
>
> Reach me @ memilanuk (at) gmail dot com
>
> ______________________________________________
> R-help at 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.
________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.
V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.
This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.
In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
More information about the R-help
mailing list