Displaying 20 results from an estimated 10000 matches similar to: "Add number series to data frame"
2012 Feb 23
2
extract subset of data.frame
Hello,
consider the following data.frame df and vector v
df <- data.frame(group = c("A","B","C","D"), value = c(1,2,3,4))
v <- c(2,3)
How can I return a sub data.frame which has only the rows left where value
matches v
df:
group value
B 2
C 3
Cheers
--
View this message in context:
2011 Dec 03
4
Data alignment
Hello!
I have a data.frame which looks like:
Name - Value
A - 400
A - 300
B - 200
B - 350
C - 500
C - 350
D - 450
D - 600
E - 700
E - 750
F - 630
F - 650
I want to add another column where all A,B should get an index 1, all C,D an
index of 2 and all E,F an index of 3 so that the data.frame looks like:
ID - Name - Value
1 - A - 400
1 - A - 300
1 - B - 200
1 - B - 350
2 - C - 500
2 - C - 350
2
2012 Feb 11
2
Detect numerical series
Hello,
I am struggling with detecting successive digits in a numerical series
vector.
Here is an example:
vec <- c(1, 15, 26, 29, 30, 31, 37, 40, 41)
I want to be able to detect 29, 30, 31 and 40, 41.
Then, I would like to delete the successive digits from the vector.
1, 15, 26, 29, 37, 40
Cheers
--
View this message in context:
2011 Oct 13
3
Create order of numbers based on a given vector
Hello!
If I have a vector vec <- c(FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE
FALSE)
I can I create the following order of numbers based on vector vec:
1, 2, 2, 3, 3, 3, 4, 5
Whenever there is a FALSE I increase the number (starting with 1).
Whenever there is a TRUE I set the same number as the previous FALSE has
been assigned to.
I would be happy for any input
Cheers,
Syrvn
--
View
2011 Dec 04
1
xyplot squeezed together
Hi,
I created the following example of a xyplot. The plot actually looks ok
apart from that the
x-axis is pretty squeezed/clinched. I tried aspect="fill" already but I want
to have all 3 sub plots
next to each other. I tried loads of different scaling varieties but with no
significant result...
library(lattice)
N <- 6
d <-
2011 Oct 06
3
Duplicate elements of a vector
Hi,
let's assume I have the following vector a:
1 5 23
How can I use R to duplicate the elements so that my new vector looks like:
1 1 5 5 23 23
Many thanks,
Syrvn
--
View this message in context: http://r.789695.n4.nabble.com/Duplicate-elements-of-a-vector-tp3879561p3879561.html
Sent from the R help mailing list archive at Nabble.com.
2011 Nov 29
2
Help needed in reproducing a plot
Hello,
can anybody tell me how to produce a plot like the one in
http://cran.r-project.org/web/packages/lme4/vignettes/Implementation.pdf
on page 13, Figure 6?
The data is stored in:
library(nlme)
data(Oats)
Cheers
--
View this message in context: http://r.789695.n4.nabble.com/Help-needed-in-reproducing-a-plot-tp4119603p4119603.html
Sent from the R help mailing list archive at
2011 Oct 13
8
Remove specific rows in a matrix/data.frame
Hi,
imagine the following matrix/data.frame
Letter Number
a 1
a 1
b 1
b 0
c 0
c 1
d 0
d 0
If the numbers for two identical letters are also identical then I want to
remove either the first or the
second row of that letter. If for a letter the numbers are 1 and 0 I want to
remove the row with the 0.
That means if the code works I would and up with the following
matrix/data.frame
Letter
2011 Aug 23
3
R system command does not work with objects/variables
Hello!
with the R system command I would like to call a perl script which needs an
input directory and an output directory in form of a path. When I put in the
path directly it works. The script line looks as follows:
system("perl '../path1' '../path2' '../path3'")
If I store the path in a variable/object and call the perl script again it
does not run and I
2011 Nov 15
2
Extract pattern from string
Hello,
with Sys.time() you get the following string:
"2011-11-15 16:25:55 GMT"
How can I extract the following substrings:
year <- 2011
month <- 11
day_time <- 15_16_25_55
Cheers,
Syrvn
--
View this message in context: http://r.789695.n4.nabble.com/Extract-pattern-from-string-tp4073432p4073432.html
Sent from the R help mailing list archive at Nabble.com.
2010 Sep 03
5
how to get row name of matrix when result is a vector
Hi,
the R code:
a <- matrix(c(1,5,4,3,7,10,34,4,3,8,6,5,12,17,45,3,2,45,46,47,3,4,22,12,21),
nrow=5)
rownames(a) <- c("a","b","c","d","e")
a
a[which(a[,3] < 8), ]
a[which(a[,3] < 6), ]
produces the following output:
> a
[,1] [,2] [,3] [,4] [,5]
a 1 10 6 3 3
b 5 34 5 2 4
c 4 4 12 45 22
d
2011 Oct 04
1
texi2dvi problem when compiling incorrect Latex code
Hello,
I am working on a big R project using Eclipse/StatET/Texlipse. I'd like to
write a Latex document within that project but DO NOT want to Sweave it.
It's pure Latex. Via the external tools configurations I set up 2 different
versions to ensure that my latex document is processed correctly.
Version 1 (System Call):
library(tools)
setwd("${container_loc}")
file =
2018 May 11
3
add one variable to a data frame
Hi All,
I have a data frame dat1:
dat1 <-data.frame(N=seq(1, 12,1), B=c("29_log","29_log", "29_log", "27_cat", "27_cat",
"1_log", "1_log", "1_log", "1_log", "1_log",
2011 Nov 26
1
dir.create() does not create directory
Hello,
I am running Windows 7 and R-2.13 in StatET.
When I try to create a directory it does not print any errors but if I check
outside eclipse if it exists or do a refresh in Eclipse the directory is not
been created. The strange thing is that it happens only to some
sub-folders... On the other hand when I use the normal windows explorer in
one of these sub-folders and create a folder it
2018 May 11
3
add one variable to a data frame
Hi Sarah,
Thank you so much!! I got your good ideas.
Ding
-----Original Message-----
From: Sarah Goslee [mailto:sarah.goslee at gmail.com]
Sent: Friday, May 11, 2018 11:40 AM
To: Ding, Yuan Chun
Cc: r-help mailing list
Subject: Re: [R] add one variable to a data frame
[Attention: This email came from an external source. Do not open attachments or click on links from unknown senders or
2011 Sep 29
1
simplest pgfSweave example results in error
Hello,
since 3 days now I try to get pgfSweave running using Eclipse + StatET.
I created a super simple .Rnw file which can be viewed here:
http://www.text-upload.com/read.php?id=147992&c=6441045 test.Rnw
When I use sweave it works perfectly fine but when I use pgfSweave I get an
error.
The R output can be viewed here:
http://www.text-upload.com/read.php?id=147995&c=3804886 R output
2018 May 11
0
add one variable to a data frame
Hi,
Here's one way to approach it, using the coercion of factor to numeric.
Note that I changed your data.frame() statement to avoid coercing
strings to factors, just to make it simpler to set the levels.
dat1 <-data.frame(N=seq(1, 12,1), B=c("29_log","29_log", "29_log",
"27_cat", "27_cat", "1_log", "1_log",
2012 Jul 08
3
list.files() find files beginning with a .
Hello,
when I use list.files with recursive = TRUE and all.files = TRUE, R returns
a list of strings/paths.
>From all those strings I want to keep only the ones starting with a .
I tried using grep to achieve that. However, the problem is that because of
the recursive list.files parameter,
for some files beginning with a . there is a path attached. I think it is
not as simple as it looks
2009 Nov 25
3
Random data
Hi,
how can I produce random data which lies around a straight line with angle
45 degree.
Similar to this image: http://zoonek2.free.fr/UNIX/48_R/g134.png
Cheers
--
View this message in context: http://old.nabble.com/Random-data-tp26513822p26513822.html
Sent from the R help mailing list archive at Nabble.com.
2018 May 11
0
add one variable to a data frame
Sarah's solutions are good, and here's another, even more basic:
tmp1 <- unique(dat1$B)
tmp2 <- seq_along(tmp1)
dat1$C <- tmp2[ match( dat1$B, tmp1) ]
> dat1
N B C
1 1 29_log 1
2 2 29_log 1
3 3 29_log 1
4 4 27_cat 2
5 5 27_cat 2
6 6 1_log 3
7 7 1_log 3
8 8 1_log 3
9 9 1_log 3
10 10 1_log 3
11 11 3_cat 4
12 12 3_cat 4
As a single line