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,
Thanks, that solved my problem!
-Lauri
2010/3/25 Gabor Grothendieck ggrothendi...@gmail.com:
Try new.row.names = 1:150 as an arg to reshape.
On Thu, Mar 25, 2010 at 2:04 PM, Lauri Nikkinen lauri.nikki...@iki.fi wrote:
Hi,
I have a data.frame in wide format which I would like to reshape
Ripley rip...@stats.ox.ac.uk:
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:
...
Error in library(package, lib.loc = lib.loc, character.only = TRUE,
logical.return = TRUE
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
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
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 -
Thanks, looking forward to that!
Happy New Year!
-Lauri
2009/12/31 Duncan Temple Lang dun...@wald.ucdavis.edu:
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.
Lauri
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 -
...@stats.uwo.ca:
On 9/8/2009 7:53 AM, Lauri Nikkinen wrote:
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
2009/9/8 Duncan Murdoch murd...@stats.uwo.ca:
On 9/8/2009 7:53 AM, Lauri Nikkinen wrote:
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
that. This seems to be hard to explain.
Regards,
L
2009/9/8 Duncan Murdoch murd...@stats.uwo.ca:
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, widths=varlength)
V1 V2 V3 V4 V5
1 DF 12
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 murd...@stats.uwo.ca:
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 every column
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.
Regards,
L
2009/9/8 Duncan Murdoch murd...@stats.uwo.ca:
On 9/8/2009 8:07 AM, 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 lauri.nikki...@iki.fi:
This is the file (see the attachment) that represents the problem I'm
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 b.rowling...@lancaster.ac.uk:
On Tue, Sep 8, 2009 at 1:52 PM, Lauri
that this is quite impossible to achieve. Thanks
anyway.
2009/9/8 Ted Harding ted.hard...@manchester.ac.uk:
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
by some char. It seem
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 lauri.nikki...@iki.fi:
Thanks
() call to
ensure that excel is properly closed each time.
Hope this helps.
Enrique
--
Date: Wed, 8 Jul 2009 16:06:57 +0300
From: Lauri Nikkinen lauri.nikki...@iki.fi
Subject: [R] RDCOMClient: how to close Excel process?
To: r-h...@stat.math.ethz.ch
Message-ID
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)
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 www...@gmail.com:
Try this:
xl$Quit()
On Wed, Jul 8, 2009 at 10:06 AM, Lauri Nikkinen lauri.nikki...@iki.fi
(and
sample_file.xls won't open).
-L
2009/7/8 Henrique Dallazuanna www...@gmail.com:
Then, you can try this:
xl - COMCreate(Excel.Application)
wk - xl$Workbooks()
sh - wk$Open(normalizePath(sample_file.xls))$Sheets()$Count()
wk$Close()
xl$Quit()
On Wed, Jul 8, 2009 at 10:19 AM, 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
Dallazuanna www...@gmail.com:
Try this:
library(RDCOMClient)
xl - COMCreate(Excel.Application)
xl$Workbooks()$Open(teste.xls)$Sheets()$Count()
On Thu, Jul 2, 2009 at 11:22 AM, Lauri Nikkinen lauri.nikki...@iki.fi
wrote:
Hi,
I'm trying to read several Excel sheets from an Excel file
Thanks, it did not work but this worked:
xl$Workbooks()$Open(\\sample_file.xls)$Sheets()$Count()
Cheers,
Lauri
2009/7/2 Henrique Dallazuanna www...@gmail.com:
Try this:
xl$Workbooks()$Open(/sample_file.xls)$Sheets()$Count()
On Thu, Jul 2, 2009 at 2:23 PM, Lauri Nikkinen lauri.nikki
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
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
), accumulate=F)
all.equal(test, g) # TRUE
As a warning, it's the first time I've ever used it myself...
Hope this helps,
baptiste
On 19 Feb 2009, at 10:21, Lauri Nikkinen wrote:
Hello,
My problem is that I would like to merge multiple files with a common
column but merge accepts only two
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 fine. I tried these solutions to my real
data, and I got an error
Error in match.names(clabs, names(xi)) :
names do not match previous
], 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 lauri.nikki...@iki.fi:
That's perfectly fine. I figured out how to to this with my second example
DF1
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
$arch
[1]
a decent-sized graph?
Regards,
Lauri
2009/2/18 Uwe Ligges lig...@statistik.tu-dortmund.de:
Lauri Nikkinen wrote:
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
), cex.axis=0.8, tick=T)
dev.off()
Regards,
Lauri
2009/2/18 Prof Brian Ripley rip...@stats.ox.ac.uk:
On Wed, 18 Feb 2009, Lauri Nikkinen wrote:
Thanks. I upgraded to R 2.8.1 and tried
tiff(filename = volc.tif, width=600, height=400, compression =
none, bg = white, res = 300)
image(t(volcano
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
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), .Label =
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 2008 2008 2008 08
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
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 text, More
}
--
--- On Tue, 10/28/08, Lauri Nikkinen [EMAIL PROTECTED] wrote:
From: Lauri Nikkinen [EMAIL PROTECTED]
Subject: [R] How to export text into separate text files
To: [EMAIL PROTECTED]
Received: Tuesday, October 28, 2008, 10:26 AM
Hello,
I'm
(paste(names(r[!is.na(r[,i]), i]), :,
as.character(r[!is.na(r[,i]), i]), \n), file=paste(temp, i,
.txt), append=T)
cat(---, \n,
file=paste(temp, i, .txt), append=T)
}
-Lauri
2008/10/28 Lauri Nikkinen [EMAIL PROTECTED]:
Thanks for the response. I have
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
) 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
df -
data.frame(month=as.character(rep(1:3,each=30)),fac=factor(rep(1:2,each=15)),
data1=round(runif(90),2
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 solution).
(length(d),10)]
--- On Wed, 20/8/08, Lauri Nikkinen [EMAIL PROTECTED] wrote:
From: Lauri Nikkinen [EMAIL PROTECTED]
Subject: [R] Random sequence of days?
To: [EMAIL PROTECTED]
Received: Wednesday, 20 August, 2008, 4:04 PM
Dear list,
I tried to find a solution for this problem from
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. I meant that the sequence should be like
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
$minor
[1] 7.1
$year
[1] 2008
$month
[1] 06
$day
[1] 23
$`svn rev`
[1] 45970
$language
[1] R
$version.string
[1] R version 2.7.1 (2008-06-23)
2008/7/4, Lauri Nikkinen [EMAIL PROTECTED]:
R users,
I'm trying to set a column width to one of the columns in a latex
table (using Hsmic
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
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)) {
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
the plot margins in a way
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 from (not a working example)
pdf(file=C
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}
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 with Windows XP and R 2.6.0
R.Version
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:
pdf.options() seems
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)
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 Of Lauri Nikkinen
Sent: Tuesday, June 17, 2008 3:08 PM
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):
---
#Taken from ?Sweave
testfile - system.file
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.
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:
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 Classes in R (R
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), 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
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 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),
var2_lab=
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-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
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
1
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 -
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
PLEASE do read
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
PLEASE do read
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
__
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 ceiling to the nearest ten?
a - 1:10*4
a
[1] 4 8 12 16 20 24
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
__
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] wrote:
Hi R-users
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
three four five
#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=f, g=g)
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(10) + 6.8
y2 - rnorm(10) + (1:10*1.7 + 1)
y3 - rnorm(10) + (1
the help,
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(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
#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(x=x,y=y, f=f,
17.1212211950981 1 NA NA 2000-01-30 1
NA NA
21 NA NA 17.8821363007311 1 NA NA NA NA
NA NA
22 NA NA 18.5939013212175 1 NA NA NA NA
NA NA
On Dec 1, 2007 8:05 AM, Lauri Nikkinen [EMAIL PROTECTED] wrote
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
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 replace the values in
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) -
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
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. I got it now
82 matches
Mail list logo