Displaying 20 results from an estimated 4000 matches similar to: "Duplicate elements of a vector"
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
2012 Feb 12
3
Vector manipulation
Hello,
I am stuck with the following problem. Consider the vector:
vec <- c(2,4,6,9,10)
I now want to use R to manipulate the vector as follows:
[1] 2, 4, 2, 6, 2, 9, 2, 10
In words, the first element of the vector should be placed in front of each
following number.
Which R commands do I need to achieve that?
Cheers
--
View this message in context:
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.
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 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
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 =
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
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
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 Oct 16
3
Which function to use: grep, replace, substr etc.?
Hello,
I have a simple question but I don't know which method is best to use for my
problem.
I have the following strings:
str1 <- "My_name_is_peter"
str2 <- "what_is_your_surname_peter"
I would like to apply predefined abbreviations for peter=p and name=n to
both strings
so that the new strings look like the followings:
str1: "My_n_is_p"
str2:
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 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 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
2010 Nov 09
3
Row-wise recurive function call
Dear Group,
I have a following dataset:
> a
A B C D
1 22 3 31 40
2 26 31 36 32
3 3 7 49 16
4 24 40 27 26
5 20 45 47 0
6 34 43 11 18
7 48 48 24 2
8 3 16 39 48
9 20 49 7 21
10 17 36 47 10
> dput(a)
structure(list(A = c(22L, 26L, 3L, 24L, 20L, 34L, 48L, 3L, 20L,
17L), B = c(3L, 31L, 7L, 40L, 45L, 43L, 48L, 16L, 49L, 36L),
C = c(31L, 36L, 49L, 27L, 47L, 11L, 24L,
2011 Jul 13
7
Error when writing to Excel files using the packages xlsx and xlsx2
Dear group,
I am working on a rather big project where the output data frames have
dimensions of 3000 x 15 or greater. We are using xlsx and xlsx2 to write the
data.frames to Excel sheets.
Since recently we get the following error, when trying to write the data
frames to the excel sheets:
Error in ls(envir = envir, all.names = private) :
invalid 'envir' argument
We figured out that
2012 Mar 06
4
Add number series to data frame
Hi,
Is there a simple way of doing the following in R?
a <- data.frame(name = c(rep("A", 3), rep("B", 5), rep("C", 10)))
> a
name
1 A
2 A
3 A
4 B
5 B
6 B
7 B
8 B
9 C
10 C
11 C
12 C
13 C
14 C
15 C
16 C
17 C
18 C
Do some fancy R code here:
> a
name val
1 A 1
2 A 2
3 A 3
4
2010 Nov 25
1
Applying function to elements of matrices in a list
Hello R-help,
Please cc me on all responses, as I only receive summary emails from
this list.
I'm wondering if anybody has any tips on how to accomplish this
efficiently. I have a list of matrices, and I'm trying to get the mean
of the [i,j]'th element of each matrix in a list.
So if I have a list of matrices, say
x <-
2011 Sep 19
2
pasting elements of one character vector together
hello,
i am familiar with the paste command with which i can paste for exaple:
object <- "Hello"
paste(object,"World")
now i would like to be able to paste all the elements of the same vector
together e.g:
object <- c("Hello","World")
getting as a result also:
"Hello World".
Does anyone know the solution to this problem?
Thank you
2012 Jan 10
4
2 sample wilcox.test != kruskal.test
Hello,
I think I am right in saying that a 2 sample wilcox.test is equal to a 2
sample kruskal.test and
a 2 sample t.test is equal to a 2 sample anova. This is also stated in the
?kruskal.test man page:
The Wilcoxon rank sum test (wilcox.test) as the special case for two
samples; lm together with anova for performing one-way location analysis
under normality assumptions; with Student's t