Re: [R] Problem with reshaping data from wide to long format

2010-03-25 Thread Lauri Nikkinen
Thanks, that solved my problem! -Lauri 2010/3/25 Gabor Grothendieck : > Try new.row.names = 1:150 as an arg to reshape. > > On Thu, Mar 25, 2010 at 2:04 PM, Lauri Nikkinen wrote: >> Hi, >> >> I have a data.frame in wide format which I would like to reshape into >

[R] Problem with reshaping data from wide to long format

2010-03-25 Thread Lauri Nikkinen
Hi, I have a data.frame in wide format which I would like to reshape into a long format: example (nonsense) data: > dput(perus2) structure(list(id = c(30L, 38L, 21L, 12L, 22L, 28L, 31L, 44L, 8L, 47L, 23L, 20L, 41L, 42L, 29L, 50L, 5L, 33L, 4L, 17L, 11L, 1L, 18L, 6L, 9L, 32L, 16L, 14L, 39L, 48L, 3

Re: [R] Problem with R on USB-drive

2010-02-09 Thread Lauri Nikkinen
i 2010/2/9, Prof Brian Ripley : > > On Tue, 9 Feb 2010, Peter Dalgaard wrote: > > Lauri Nikkinen wrote: >> >>> Hi, >>> >>> I installed R on USB-drive, but when I run Rgui.exe from bin folder, I >>> get >>> this error: >>&g

[R] Problem with R on USB-drive

2010-02-08 Thread Lauri Nikkinen
Hi, I installed R on USB-drive, but when I run Rgui.exe from bin folder, I get this error: --- R version 2.10.1 (2009-12-14) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welc

Re: [R] XML and RCurl: problem with encoding (htmlTreeParse)

2010-01-01 Thread Lauri Nikkinen
Thanks. Interestingly, your code works on my Mac 10.6.1 but not on my Win XP. See sessionInfo from below. Mac R: > sessionInfo() R version 2.9.2 (2009-08-24) i386-apple-darwin8.11.1 locale: fi_FI.UTF-8/fi_FI.UTF-8/C/C/fi_FI.UTF-8/fi_FI.UTF-8 attached base packages: [1] stats graphics grDevi

Re: [R] XML and RCurl: problem with encoding (htmlTreeParse)

2009-12-31 Thread Lauri Nikkinen
Thanks, looking forward to that! Happy New Year! -Lauri 2009/12/31 Duncan Temple Lang : > Hi Lauri. > > I am in the process of making some changes > to the encoding in the XML package. I'll take a look > over the next few days. (Not certain precisely when.) > >  D. &g

[R] XML and RCurl: problem with encoding (htmlTreeParse)

2009-12-31 Thread Lauri Nikkinen
Hi, I'm trying to get data from web page and modify it in R. I have a problem with encoding. I'm not able to get encoding right in htmlTreeParse command. See below > library(RCurl) > library(XML) > > site <- getURL("http://www.aarresaari.net/jobboard/jobs.html";) > txt <- readLines(tc <- textConn

Re: [R] Data separated by spaces, getting data into R using fiel

2009-09-08 Thread Lauri Nikkinen
that this is quite impossible to achieve. Thanks anyway. 2009/9/8 Ted Harding : > On 08-Sep-09 16:17:00, David Winsemius wrote: >> On Sep 8, 2009, at 12:00 PM, Lauri Nikkinen wrote: >>> Ok, I think that I have to give up and try to get this data separated >>> b

Re: [R] Data separated by spaces, getting data into R using field lengths

2009-09-08 Thread Lauri Nikkinen
Ok, I think that I have to give up and try to get this data separated by some char. It seem pretty much impossible to separate those fields. Thanks for your help and efforts. -L 2009/9/8 Lauri Nikkinen : > This is the file (see the attachment) that represents the problem I'm > faci

Re: [R] Data separated by spaces, getting data into R using field lengths

2009-09-08 Thread Lauri Nikkinen
This is the file (see the attachment) that represents the problem I'm facing with the original file. I'm looking for some generic way to solve this problem. Thank you for your time. -L 2009/9/8 Barry Rowlingson : > On Tue, Sep 8, 2009 at 1:52 PM, Lauri Nikkinen wrote: > >&g

Re: [R] Data separated by spaces, getting data into R using field lengths

2009-09-08 Thread Lauri Nikkinen
column has a maximum length and I want to >> use this maximum length as a separator. So if one "cell" in that >> column is shorter than the maximum, "cell" should be padded with white >> spaces or something like that. This seems to be hard to explain. >> &g

Re: [R] Data separated by spaces, getting data into R using field lengths

2009-09-08 Thread Lauri Nikkinen
Thanks for the suggestion, but I don't have an access to this database, I just got this messy file. -L 2009/9/8 Duncan Murdoch : > On 9/8/2009 8:21 AM, Lauri Nikkinen wrote: >> >> This data is from database and the maximum length of a field is >> defined. I mean that

Re: [R] Data separated by spaces, getting data into R using field lengths

2009-09-08 Thread Lauri Nikkinen
something like that. This seems to be hard to explain. Regards, L 2009/9/8 Duncan Murdoch : > On 9/8/2009 8:07 AM, Lauri Nikkinen wrote: >> >> Thanks, I tried it but I got >> >>> varlength <- c(2, 2, 18, 5, 18) >>> read.fwf("c:temppi.txt", width

Re: [R] Data separated by spaces, getting data into R using field lengths

2009-09-08 Thread Lauri Nikkinen
is a", " This is 12334 Thi", >>    " This is an 1232 T", " This is an exampl"), class = "factor"), >>    V4 = structure(c(1L, 2L, 4L, 3L), .Label = c("e 1 T", "his i", >>    "n exa", "s is "),

Re: [R] Data separated by spaces, getting data into R using field lengths

2009-09-08 Thread Lauri Nikkinen
.Label = c("an ", "his", "mple", "s"), class = "factor")), .Names = c("V1", "V2", "V3", "V4", "V5"), class = "data.frame", row.names = c(NA, -4L)) Any ideas? -L 2009/9/8 Duncan Murdoch : &g

[R] Data separated by spaces, getting data into R using field lengths

2009-09-08 Thread Lauri Nikkinen
I have a text file similar to this (separated by spaces): x <- "DF12 This is an example 1 This DF12 This is an 1232 This is DF14 This is 12334 This is an DF15 This 23 This is an example " and I know the field lengths of each variable (there is 5 variables in this data set), which are: varlength

Re: [R] R-help Digest, Vol 77, Issue 9

2009-07-09 Thread Lauri Nikkinen
runs of your code that failed). If your code is > inside a function, wrap the code in point 1 and 2 on an on.exit() call to > ensure that excel is properly closed each time. > > > Hope this helps. > > Enrique > > -- > > Date:

Re: [R] RDCOMClient: how to close Excel process?

2009-07-09 Thread Lauri Nikkinen
This solution worked: nBooks <- xl[["Workbooks"]]$Count(); for (i in seq_len(nBooks)) xl[["Workbooks"]]$item(i)$Close(SaveChanges=FALSE); from http://www.mail-archive.com/r-help@r-project.org/msg61498.html Thanks! -L 2009/7/9 Lauri Nikkinen : &

Re: [R] RDCOMClient: how to close Excel process?

2009-07-08 Thread Lauri Nikkinen
e_file.xls"))$Sheets()$Count() > > wk$Close() > xl$Quit() > > > > On Wed, Jul 8, 2009 at 10:19 AM, Lauri Nikkinen > wrote: >> >> Thanks but that did not work. xl$Quit() does not kill the Excel >> process and sample_file.xls will not open. >> >

Re: [R] RDCOMClient: how to close Excel process?

2009-07-08 Thread Lauri Nikkinen
Thanks but that did not work. xl$Quit() does not kill the Excel process and sample_file.xls will not open. I'm using Windows XP SP2 and R 2.8.1 -L 2009/7/8 Henrique Dallazuanna : > Try this: > > xl$Quit() > > On Wed, Jul 8, 2009 at 10:06 AM, Lauri Nikkinen > wrote: >

[R] RDCOMClient: how to close Excel process?

2009-07-08 Thread Lauri Nikkinen
Hi, I’m using R package RDCOMClient (http://www.omegahat.org/RDCOMClient/) to retrieve data from MS Excel workbook. I’m using the code below to count the number of sheets in the workbook and then loop the data from sheets in to a list. # R code ### library(gdata) libra

Re: [R] read.xls: number of sheets

2009-07-02 Thread Lauri Nikkinen
Thanks, it did not work but this worked: xl$Workbooks()$Open("\\sample_file.xls")$Sheets()$Count() Cheers, Lauri 2009/7/2 Henrique Dallazuanna : > Try this: > > xl$Workbooks()$Open("/sample_file.xls")$Sheets()$Count() > > On Thu, Jul 2, 2009 at 2:23 PM, Lauri

Re: [R] read.xls: number of sheets

2009-07-02 Thread Lauri Nikkinen
moved, or deleted. (Microsoft Excel) > Any ideas how to proceed? -L 2009/7/2 Henrique Dallazuanna : > Try this: > > > library(RDCOMClient) > > xl <- COMCreate("Excel.Application") > xl$Workbooks()$Open("teste.xls")$Sheets()$Count() > > > On Th

[R] read.xls: number of sheets

2009-07-02 Thread Lauri Nikkinen
Hi, I'm trying to read several Excel sheets from an Excel file into a list. I'm using read.xls from package 'gdata'. I would like to know how I can check the number of sheets before the loop (in the example below) so that I could adjust the loop counter? Any suggestions? DF.list <- list() for (i

[R] R Golf?

2009-04-20 Thread Lauri Nikkinen
Hello, This is probably off-topic but have the R community ever organized R Golf contents similar to Perl Golf: http://perlgolf.sourceforge.net/ ? It would be nice to see how R gurus solve problems in many different ways (although you see it at this list every day :-)). Regards, -L _

Re: [R] Multiple merge, better solution?

2009-02-19 Thread Lauri Nikkinen
= letters[8:12], a = rnorm(5), b = rnorm(5), c = rnorm(5)) DF <- DF1 for ( .df in list(DF2,DF3,DF4) ) { DF <-merge(DF,.df,by.x="var1", by.y="var1", all=T, suffixes=c("", "")) } DF -Lauri 2009/2/19 Lauri Nikkinen : > That's perfectly

Re: [R] Multiple merge, better solution?

2009-02-19 Thread Lauri Nikkinen
ge > > It would be very nice if a R guru could check that the information I put is > not complete fantasy. Feel free to remove as appropriate. > > Best wishes, > > baptiste > > > On 19 Feb 2009, at 11:00, Lauri Nikkinen wrote: > >> Thanks, both solutions work f

Re: [R] Multiple merge, better solution?

2009-02-19 Thread Lauri Nikkinen
by.y="var1", all=T) > g <- merge(g, DF3, by.x="var1", by.y="var1", all=T) > g <- merge(g, DF4, by.x="var1", by.y="var1", all=T) > > test <- Reduce(function(x, y) merge(x, y, all=T,by.x="var1", by.y="var1"), >

[R] Multiple merge, better solution?

2009-02-19 Thread Lauri Nikkinen
Hello, My problem is that I would like to merge multiple files with a common column but merge accepts only two data.frames to merge. In the real situation, I have 26 different data.frames with a common column. I can of course use merge many times (see below) but what would be more sophisticated so

Re: [R] bitmap .tif in colors

2009-02-18 Thread Lauri Nikkinen
0, 1, 0.1), cex.axis=0.8, tick=T) axis(2, at=seq(0, 1, 0.1), cex.axis=0.8, tick=T) dev.off() Regards, Lauri 2009/2/18 Prof Brian Ripley : > On Wed, 18 Feb 2009, Lauri Nikkinen wrote: > >> Thanks. I upgraded to R 2.8.1 and tried >> >> tiff(filename = "volc.tif",

Re: [R] bitmap .tif in colors

2009-02-18 Thread Lauri Nikkinen
should be modified to produce a decent-sized graph? Regards, Lauri 2009/2/18 Uwe Ligges : > > > Lauri Nikkinen wrote: >> >> Hello, >> >> How to produce .tif graphic in colors using bitmap function? >> >> e.g this produces figure in grayscale >>

[R] bitmap .tif in colors

2009-02-18 Thread Lauri Nikkinen
Hello, How to produce .tif graphic in colors using bitmap function? e.g this produces figure in grayscale bitmap(file="volc.tif", type = "tifflzw", res = 300) image(t(volcano)[ncol(volcano):1,]) dev.off() I'm using Windows XP and ghostscript. > R.Version() $platform [1] "i386-pc-mingw32" $arc

Re: [R] Merge or combine data frames with missing columns

2008-12-29 Thread Lauri Nikkinen
How about this solution g1 <- data.frame(ic = 1, y1 = 2, y2 = 3, y3 = 4, y4 = 5) g2 <- data.frame(ic = 2, y2 = 6, y3 = 7) g <- list(g1, g2) library(gregmisc) do.call(smartbind, g) -Lauri __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman

[R] complex(?) reshaping question

2008-12-05 Thread Lauri Nikkinen
Hello, I have a problem with data reshaping. Here's my data DF <- structure(list(idvar1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("patient1", "patient2" ), class = "factor"), idvar2 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Lab

[R] regexp help needed

2008-11-28 Thread Lauri Nikkinen
Hello, I have a vector of dates and I would like to grep the year component from this vector (= all digits after the last punctuation character) dates <- c("28.7.08","28.7.2008","28/7/08", "28/7/2008", "28/07/2008", "28-07-2008", "28-07-08") the resulting vector should look like "08" "2008" "08

[R] How to split DF into a list and avoid NULL elements in this list

2008-11-25 Thread Lauri Nikkinen
Hello, I'm trying to split my DF into a list using incremental loop. How can I avoid NULL elements in this list? DF <- data.frame(var1 = 1:10, var2 = 11:20, var3 = 21:30, var4 = 31:40) x <- list() i <- 1 while (i <= ncol(DF)-1) { x[[i]] <- DF[, i:c(i+1)] i <- i + 2 } x Many

Re: [R] How to export text into separate text files

2008-10-28 Thread Lauri Nikkinen
ot;, file=paste("temp", i, ".txt"), append=T) cat("\n", file=paste("temp", i, ".txt"), append=T) cat(paste(names(r[!is.na(r[,i]), i]), ":", as.character(r[!is.na(r[,i]), i]), "\n"), file=paste("temp",

Re: [R] How to export text into separate text files

2008-10-28 Thread Lauri Nikkinen
im Holtman's suggestion. > - > > for (i in 2:4){ >input <- read.delim(paste('vegetation_', i, '.txt', sep='')) > process the file > } > > -

[R] How to export text into separate text files

2008-10-28 Thread Lauri Nikkinen
Hello, I'm producing text from my data.frame using cat function. I would like to use for loop to export each column in my data.frame into separate text files. Here is the example code r <- t(Indometh) for (i in 1:ncol(r)) { cat("Some text,", "\n") cat("\n") cat("More text, More tex

Re: [R] List of sublists

2008-10-01 Thread Lauri Nikkinen
> lapply(split(df, df$month), function(x) split(x, x$fac)) > > > I hope it helps. > > Best, > Dimitris > > > Lauri Nikkinen wrote: > >> R users, >> >> I would like to split this df by month and fac and produce list of >> sublists >&

[R] List of sublists

2008-10-01 Thread Lauri Nikkinen
R users, I would like to split this df by month and fac and produce list of sublists df <- data.frame(month=as.character(rep(1:3,each=30)),fac=factor(rep(1:2,each=15)), data1=round(runif(90),2), data2=round(runif(90),2)) This split(df, paste(df$month, df$fac)) produces

Re: [R] Random sequence of days?

2008-08-19 Thread Lauri Nikkinen
Thanks Jeff for pointing me the right direction. "Consecutive" was the right word. This will do it d.samp <- sample(d[1:(length(d)-10)], 1) seq(d.samp, d.samp+10, by="days") Regards, Lauri 2008/8/20, Lauri Nikkinen <[EMAIL PROTECTED]>: > Thanks for quick reply.

Re: [R] Random sequence of days?

2008-08-19 Thread Lauri Nikkinen
25" so that the the days are adjacent... -Lauri 2008/8/20, Moshe Olshansky <[EMAIL PROTECTED]>: > How about > > d[sample(length(d),10)] > > > --- On Wed, 20/8/08, Lauri Nikkinen <[EMAIL PROTECTED]> wrote: > > > From: Lauri Nikkinen <[EMAIL PROTECTED]&g

[R] Random sequence of days?

2008-08-19 Thread Lauri Nikkinen
Dear list, I tried to find a solution for this problem from the archives but couldn't find any. I would like sample sequence of ten days from vector d d <- seq(as.Date("2007-02-12"), as.Date("2008-08-18"), by="days") so that the days follow each other (sample(d, 10) is not the appropriate soluti

[R] List of "occurrence" matrices

2008-08-07 Thread Lauri Nikkinen
R users, I don't know if I can make myself clear but I'll give it a try. I have a data.frame like this x <- "var1,var2,var3,var4 a,b,b,a b,b,c,b c,a,a,a a,b,c,c b,a,c,a c,c,b,b a,c,a,b b,c,a,c c,a,b,c" DF <- read.table(textConnection(x), header=T, sep=",") DF and I would like to sum all the com

Re: [R] Hmisc latex: table column width

2008-07-07 Thread Lauri Nikkinen
## > R.Version() $platform [1] "i386-pc-mingw32" $arch [1] "i386" $os [1] "mingw32" $system [1] "i386, mingw32" $status [1] "" $major [1] "2" $minor [1] "7.1" $year [1] "2008" $month [1] "06" $d

[R] Hmisc latex: table column width

2008-07-04 Thread Lauri Nikkinen
R users, I'm trying to set a column width to one of the columns in a latex table (using Hsmic package, latex function). My intention is to get \begin{tabular}{lp{1.2in}ll}\hline\hline Here's an example ### R code # DF <- data.frame(Titanic) DF$long <- paste("This is a ve

Re: [R] Plotting question: Problem with strwidth in 2.7.1

2008-06-30 Thread Lauri Nikkinen
Sorry, I found that there is a new bmp() device and when I lower the resolution parameter e.g. to 72, everything works fine. Best Lauri 2008/6/30, Lauri Nikkinen <[EMAIL PROTECTED]>: > R users, > > I have a problem with function strwidth in 2.7.1. I'm trying to set > th

[R] Plotting question: Problem with strwidth in 2.7.1

2008-06-30 Thread Lauri Nikkinen
R users, I have a problem with function strwidth in 2.7.1. I'm trying to set the plot margins in a way that horizontal column labels will fit to the graph. tmp.t is a list of data.frame objects. This code works well in 2.6.0. ...snip.. library(gplots) for (i in names(tmp.t)) { bmp(filen

Re: [R] Sweave: controlling pointsize (pdf)

2008-06-27 Thread Lauri Nikkinen
Yes, I think so too. I already tried with options(SweaveHooks=list(fig=function() pdf(pointsize=10))) but as you said it tries to open pdf device and Sweaving fails... Best Lauri 2008/6/27, Duncan Murdoch <[EMAIL PROTECTED]>: > On 27/06/2008 7:12 AM, Lauri Nikkinen wrote: > &

Re: [R] Sweave: controlling pointsize (pdf)

2008-06-27 Thread Lauri Nikkinen
pdf.options() seems to be a new function (from 2.7.0), so I quess I'll have to upgrade or write my own hook function for Sweave. Thanks. Best Lauri 2008/6/27, Duncan Murdoch <[EMAIL PROTECTED]>: > On 27/06/2008 6:23 AM, Lauri Nikkinen wrote: > > I'm working wi

[R] Sweave: controlling pointsize (pdf)

2008-06-27 Thread Lauri Nikkinen
Hello, Is there a way to control pointsize of pdf:s produced by Sweave? I would like to have the same pointsize from (not a working example) pdf(file="C:/temp/example.pdf", width=7, height=7, bg="white", pointsize=10) plot(1:10) etc.. dev.off() as \documentclass[a4paper]{article} \usepackage[la

Re: [R] Sweave: controlling pointsize (pdf)

2008-06-27 Thread Lauri Nikkinen
I'm working with Windows XP and R 2.6.0 > R.Version() $platform [1] "i386-pc-mingw32" -Lauri 2008/6/27, Lauri Nikkinen <[EMAIL PROTECTED]>: > Hello, > > Is there a way to control pointsize of pdf:s produced by Sweave? I > would like to have the same pointsize

Re: [R] Sweave: problem with usepackage{C:/PROGRA~1/R/R-27~1.0/share/texmf/Sweave}

2008-06-17 Thread Lauri Nikkinen
l/r-devel/2008-May/049609.html > > On Tue, Jun 17, 2008 at 3:08 PM, Lauri Nikkinen <[EMAIL PROTECTED]> wrote: > > R users, > > > > I'm at a loss with a problem considering running .tex files produced > > by Sweave. When I run (R 2.7.0): > > ---

Re: [R] Sweave: problem withusepackage{C:/PROGRA~1/R/R-27~1.0/share/texmf/Sweave}

2008-06-17 Thread Lauri Nikkinen
irectory. > > I ended up setting up a C:\programs\ and putting all my unix-happy programs > (R, latex, etc) there to ensure path spaces don't screw me up when running > under windows. > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf

[R] Sweave: problem with usepackage{C:/PROGRA~1/R/R-27~1.0/share/texmf/Sweave}

2008-06-17 Thread Lauri Nikkinen
R users, I'm at a loss with a problem considering running .tex files produced by Sweave. When I run (R 2.7.0): --- #Taken from ?Sweave testfile <- system.file("Sweave", "Sweave-test-1.Rnw", package = "utils") ## enforce par(ask=FALSE) options(device

[R] Summary statistics across factor levels

2008-04-30 Thread Lauri Nikkinen
R users, I intention is to calculate some summary statistics across factor levels. I know that in Hmisc package there is a summary function which produces neat summary statistics when using "cross" option. I would like to produce similar output with N and Missing columns but produce a data.frame.

[R] How to schedule R scripts?

2008-03-27 Thread Lauri Nikkinen
useRs, Is there a way to schedule R scripts? I would like to run certain scripts three times a day. I'm running R on Windows XP. > sessionInfo() R version 2.6.0 (2007-10-03) i386-pc-mingw32 locale: LC_COLLATE=Finnish_Finland.1252;LC_CTYPE=Finnish_Finland.1252;LC_MONETARY=Finnish_Finland.1252;LC_

Re: [R] How to get week of the year, scale 1-52?

2008-03-18 Thread Lauri Nikkinen
u have more than 52 weeks in each > year. > > > --- Lauri Nikkinen <[EMAIL PROTECTED]> wrote: > > > R users, > > > > I have a vector of dates > > > > days <- seq(as.Date("2007/1/1"), > > as.Date("2008/1/31"), "d

[R] How to get week of the year, scale 1-52?

2008-03-18 Thread Lauri Nikkinen
R users, I have a vector of dates days <- seq(as.Date("2007/1/1"), as.Date("2008/1/31"), "days") and I would like to have week numbers from 1 to 52 for each year. How do I do that? Now I get 00-53 using format(days, "%W") > range(format(days, "%W")) [1] "00" "53" I have read "Date and Time Cl

[R] How to export tables in list separately using write.table or sink?

2008-02-28 Thread Lauri Nikkinen
R users, My intention is to take factors out of DF, create list of tables and export these tables separately using write.table or sink function. write.table writes tables out as DF:s, should I use sink instead? Here is my example: a <- data.frame(indx =1:20, var1 =

[R] Combining series of variables using identifier

2008-02-26 Thread Lauri Nikkinen
R users, I have df like this a <- data.frame(indx =1:20, var1 =rep(c("I20", "I40", "A50", "B60"), each=5), var1_lab= rep(c("cat", "dog", "mouse", "horse"), each=5), var2 =rep(c("B20", "X40", "D50", "G60"), each=5),

[R] How to get names of a list into df:s?

2008-02-21 Thread Lauri Nikkinen
R users, I have a simple lapply question. g <- list(a=1:3, b=4:6, c=7:9) g <- lapply(g, function(x) as.data.frame(x)) lapply(g, function(x) cbind(x, var1 = rep(names(g), each=nrow(x))[1:nrow(x)])) I get $a x var1 1 1a 2 2a 3 3a $b x var1 1 4a 2 5a 3 6a $c x var1

Re: [R] Selecting timestamps

2008-02-21 Thread Lauri Nikkinen
is left as an easy > exercise. > > Bill Venables > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On Behalf Of Lauri Nikkinen > Sent: Thursday, 21 February 2008 5:04 PM > To: [EMAIL PROTECTED] > Subject: [R] Selecting timestamps > >

[R] Selecting timestamps

2008-02-20 Thread Lauri Nikkinen
R-users, I have two vectors (of timestamps) d1 <- as.POSIXct(strptime("2.2.2002 07:00", format="%d.%m.%Y %H:%M")) d2 <- as.POSIXct(strptime("4.2.2002 07:00", format="%d.%m.%Y %H:%M")) seq1 <- seq(d1, d2, "hours") seq1 d3 <- as.POSIXct(strptime("2.2.2002 15:22", format="%d.%m.%Y %H:%M")) d4 <- as

[R] (Small) problem with barchart

2008-02-03 Thread Lauri Nikkinen
Perhaps, letters <- c("f","a", "j","i","d","e") a <- c(18,15,12,12,9,6) df <- data.frame(letters, a) library(lattice) barchart(reorder(df$letters, df$a) ~ df$a) -Lauri __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help P

[R] How do I get a character and a symbol in a legend

2008-01-23 Thread Lauri Nikkinen
Perhaps: plot(1:10,1:10,type="n") points(1:5,1:5,pch="+") points(6:10,6:10,pch=20) legend(5,5, c("A","B"), pch=c("+", NA)) legend(5,5, c("A","B"), pch=c(NA, 20)) -Lauri __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help P

Re: [R] Ceiling to the nearest ten?

2008-01-14 Thread Lauri Nikkinen
Oh, yeah, too simple... Thank you all! 2008/1/14, Richard M. Heiberger <[EMAIL PROTECTED]>: > > a <- 1:10*4 > > ceiling(a/10)*10 > [1] 10 10 20 20 20 30 30 40 40 40 > > > > -Original Message- > Lauri Nikkinen > > Is there a function for ce

[R] Ceiling to the nearest ten?

2008-01-14 Thread Lauri Nikkinen
R-users, Is there a function for ceiling to the nearest ten? a <- 1:10*4 a [1] 4 8 12 16 20 24 28 32 36 40 The resulting vector should look like this ("ceiling to the nearest ten") [1] 10 10 20 20 20 30 30 40 40 40 Thanks in advance Lauri __ R-help

Re: [R] How to add rowSums into list?

2008-01-11 Thread Lauri Nikkinen
Thanks, one further question: how to order these matrices using these row sums? lapply(a, function(x) order(x[,5])) #produces only indeces -Lauri 2008/1/11, Henrique Dallazuanna <[EMAIL PROTECTED]>: > lapply(a, addmargins, 2) > > On 11/01/2008, Lauri Nikkinen <[EMAIL PROTECTED

[R] How to add rowSums into list?

2008-01-11 Thread Lauri Nikkinen
Hi R-users, I have a list a <- list(one=matrix(rnorm(20), 5, 4), two=matrix(rnorm(20, 3, 0.5),5,4)) How to add rowSums (calculated using lapply) to corresponding matrix in this list lapply(a, function(x) rowSums(x)) ?? -Lauri __ R-help@r-project.or

[R] Subsetting array (NA:s)

2008-01-10 Thread Lauri Nikkinen
Hi R-users, I have an array similar to this: tmp <- array(1:6, c(2,3,3)) n1 <- c("one", "two") n2 <- c("three", "four", "five") n3 <- c("six", "seven", "eight") dimnames(tmp) <- list(n1, n2, n3) tmp[1,,1] <- NA tmp[1,3,2] <- NA tmp[2,,3] <- NA tmp How to subset !is.na(x) rows resulting , , six

Re: [R] How to recode a factor level (within the list)?

2007-12-02 Thread Lauri Nikkinen
x y f g wdays "integer" "numeric""factor" "Date" "character" Really appreciate the help, Lauri 2007/12/2, Prof Brian Ripley <[EMAIL PROTECTED]>: > On Sun, 2 Dec 2007, Lauri Nikkinen wrote:

Re: [R] How to recode a factor level (within the list)?

2007-12-02 Thread Lauri Nikkinen
Thank you Prof Ripley for your solutions, I'll get by with these. Lauri 2007/12/2, Prof Brian Ripley <[EMAIL PROTECTED]>: > On Sun, 2 Dec 2007, Lauri Nikkinen wrote: > > > #Dear R-users, > > #I have a data.frame like this: > > > > y1 <- rnorm(1

[R] How to recode a factor level (within the list)?

2007-12-02 Thread Lauri Nikkinen
#Dear R-users, #I have a data.frame like this: y1 <- rnorm(10) + 6.8 y2 <- rnorm(10) + (1:10*1.7 + 1) y3 <- rnorm(10) + (1:10*6.7 + 3.7) y <- c(y1,y2,y3) x <- rep(1:3,10) f <- gl(2,15, labels=paste("lev", 1:2, sep="")) g <- seq(as.Date("2000/1/1"), by="day", length=30) DF <- data.frame(x=x,y=y, f=

Re: [R] How to cbind DF:s with differing number of rows?

2007-12-01 Thread Lauri Nikkinen
NA > 15 NA 10.6249309181431 1 NA 2000-01-23 1 >NA > 16 NA 11.1550663909848 1 NA 2000-01-24 1 >NA > 17 NA 11.3189773716082 1 NA 2000-01-26 1 >NA > 18 NA 12.8838097369011

[R] How to cbind DF:s with differing number of rows?

2007-12-01 Thread Lauri Nikkinen
#Hi R-users, #Suppose that I have a data.frame like this: y1 <- rnorm(10) + 6.8 y2 <- rnorm(10) + (1:10*1.7 + 1) y3 <- rnorm(10) + (1:10*6.7 + 3.7) y <- c(y1,y2,y3) x <- rep(1:3,10) f <- gl(2,15, labels=paste("lev", 1:2, sep="")) g <- seq(as.Date("2000/1/1"), by="day", length=30) DF <- data.frame(

[R] How to count the number of sequences in matrix?

2007-11-13 Thread Lauri Nikkinen
Hi R-users, I have a matrix similar to this. I would like to calculate the number of 1 sequences in a row and also the length of the 1 sequence. For instance, in the example below, row number one has four sequences of number 1 (from left to right: 1; 1; 1,1; 1) and the corresponding SeqCount is 4

[R] Match and replace between two data.frames

2007-10-24 Thread Lauri Nikkinen
Hi folks, I have two dataframes like these: DF <- data.frame(ID=c("AA1234","AB3233","AC4353","AD2345","AE7453"), CK32344=c(1,3,2,4,1), CK32664=c(2,1,1,2,3), CK33422=c(2,2,1,3,2)) VAL <- data.frame(num=rep(6,3), type=c("CK32344", "CK32664", "CK33422"), number=c("32","452","234")) I want to replac

[R] Variable which has the maximum value of DF

2007-10-15 Thread Lauri Nikkinen
Hi, Suppose I have a data.frame like this Lines <- "var1 var2 var3 var4 var5 var6 0 2 1 2 0 0 2 3 7 6 0 1 1.54 9 9 6 0 1.06 1022 3 3 " DF <- read.table(textConnection(Lines), skip=1) names(DF) <-

Re: [R] Calculating group means using self-written function

2007-10-02 Thread Lauri Nikkinen
Well, I finally found a roundabout fun <- function(x, y) sum(x)/max(y) aggregate(vsid$lev, list(vsid$month, vsid$year), fun, y=by(vsid$date, vsid$month, function(x) length(unique(x Thanks, Lauri 2007/10/2, Lauri Nikkinen <[EMAIL PROTECTED]>: > Thanks Petr for your kind answer.

Re: [R] Calculating group means using self-written function

2007-10-02 Thread Lauri Nikkinen
Thanks Petr for your kind answer. I got it now but it seems that argument y will not be split by "list(vsid$month, vsid$year)" in the aggregate function. I should get number of days in each month in the denominator with "length(unique(y))" but instead I get sum of days in months in the denominator.

Re: [R] Calculating group means using self-written function

2007-10-02 Thread Lauri Nikkinen
Thanks Petr, Yes, your code seems to work. But when I try to reproduce it with my original data set fun <- function(x, y) sum(x)/length(unique(y)) aggregate(vsid$lev, list(vsid$month, vsid$yeari), fun, vsid$lev=vsid$date) I get Error: syntax error, unexpected EQ_ASSIGN, expecting ',' in "aggreg

[R] Calculating group means using self-written function

2007-10-02 Thread Lauri Nikkinen
Hi R-users, Suppose I have a following data set. y1 <- rnorm(20) + 6.8 y2 <- rnorm(20) + (1:20*1.7 + 1) y3 <- rnorm(20) + (1:20*6.7 + 3.7) y <- c(y1,y2,y3) var1 <- rep(1:5,12) z <- rep(1:6,10) f <- gl(3,20, labels=paste("lev", 1:3, sep="")) d <- data.frame(var1=var1, z=z,y=y, f=f) Using followin