Displaying 20 results from an estimated 8000 matches similar to: "Vector manipulation"
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 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 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 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 =
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 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
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
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
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 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
2008 Dec 02
1
merge character strings
Hi,
how can I do the following in R?:
vec <- c("a", "b", "c")
....magic.....
print(str)
"abc"
or even better:
"(a,b,c)"?
Cheers
--
View this message in context: http://www.nabble.com/merge-character-strings-tp20790116p20790116.html
Sent from the R help mailing list archive at Nabble.com.
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
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
2010 Jul 14
1
convert data.frame to matrix -> NA factor problem
Hi list,
I tried to convert a data.frame into a matrix using data.matrix.
Unfortunately my matrix contains missing values (NA) wherefore all columns
including NA's were changed into factors.
I thought that many people stumbled across that problem already wherefore
there must be a
simple solution. But it seems there isn't. I tried lapply, replace and other
things in combination
but still