Displaying 20 results from an estimated 7000 matches similar to: "Matrix subsetting with rownames"
2017 Nov 22
1
`[<-.data.frame` sets rownames incorrectly
Hi,
Here is another problem with data frame subsetting:
> df <- data.frame(aa=1:3)
> value <- data.frame(aa=11:12, row.names=c("A", "B"))
> `[<-`(df, 4:5, , value=value)
aa
1 1
2 2
3 3
A 11
B 12
> `[<-`(df, 5:4, , value=value)
aa
1 1
2 2
3 3
B 12
A 11
For this last result, the rownames of the
2023 May 03
1
Inquiry about the behaviour of subsetting and names in matrices
Hello,
I have stumbled upon a few cases where the behaviour of naming and subsetting in matrices seems unintuitive.
All those look related so wanted to put everything in one message.
1. Why row/col selection by names with NAs is not allowed?
x <- setNames(1:10, letters[1:10])
X <- matrix(x, nrow=2, dimnames = list(letters[1:2], LETTERS[1:5]))
x[c(1, NA, 3)] # vector: works
2007 Jan 24
3
Capturing output from external executables, in windows
Hi,
Any help on the following would be much appreciated
I wish to capture the output (currently going to console) from an
external executable.
The executable is successfully run using
system("program -switch ")
and the output printed to the DOS console.
How do I capture this output? I have tried redirecting the output to a
text file, and then reading this in
2012 Apr 26
2
Subsetting dataframe with missing values
Dear R-community,
I am using R (V 2.14.1) on Windows 7. I have a dataset which consists of 19
variables for 91 individuals or rows. Two of my variables are Age
(adult/chick, with no NA values) and Sex (0 for females/1 for females, with
quite a few NA values). The sex of many adult birds is unknown (entered as
NA in dataframe). At some point of my analyses, I happen to need to need to
work with
2003 Jun 12
9
Programcode and data in the same textfile
I have the following problem. It is not of earthshaking importance,
but still I have spent a considerable amount of time thinking about
it.
PROBLEM: Is there any way I can have a single textfile that contains
both
a) data
b) programcode
The program should act on the data, if the textfile is source()'ed
into R.
BOUNDARY CONDITION: I want the data written in the textfile in exactly
2002 Nov 22
2
Need help with pipe()
Hello.
I have an R program that calls gawk (GNU Awk 3.06 for Windows) from
within pipe() to preprocess a large file before it is read into a data
frame with read.table().
I've recently upgraded from Win98SE to WinXP, and have also upgraded
from R1.5.0 to R1.6.1 over the past month or so. This program worked
before the upgrade(s), but now fails. I observe the following sort of
behavior with
2023 May 03
1
Inquiry about the behaviour of subsetting and names in matrices
Karolis wrote:
> Hello,
> I have stumbled upon a few cases where the behaviour of naming and subsetting in matrices seems unintuitive.
> All those look related so wanted to put everything in one message.
> 1. Why row/col selection by names with NAs is not allowed?
> x <- setNames(1:10, letters[1:10])
> X <- matrix(x, nrow=2, dimnames = list(letters[1:2],
2018 Nov 21
2
Subsetting row in single column matrix drops names in resulting vector
Hello here. I'm struggling to understand R's subsetting behavior in couple
of edge cases - subsetting row in a single column matrix and subsetting
column in a single row matrix. I've read R's docs several times and haven't
found answer.
Consider following example:
a = matrix(1:2, nrow = 2, dimnames = list(c("row1", "row2"), c("col1")))
a[1, ]
# 1
2005 Feb 17
1
Subsetting using dimnames on S4 array-based class
Hello,
I did send this message to r-help and got no reply, no I am resubmitting
here in case this was a bit too specific for the other list.
Many thanks,
Iago
From:
Iago Mosqueira
<imosqueira@suk.azti.es>
To:
r-help@stat.math.ethz.ch
Subject:
Subsetting using dimnames on S4
array-based class
2012 Aug 15
1
hidden for() loop subsetting a matrix?
Hi,
I am subsetting a matrix thus:
test
[,1] [,2] [,3]
[1,] 1 7 13
[2,] 2 8 14
[3,] 3 9 15
[4,] 4 10 16
[5,] 5 11 17
[6,] 6 12 18
test[cbind(c(1,3,5), c(2,1,3))]
[1] 7 3 17
This works fine, and is the equivalent of c(test[1,2], test[3,1], test[5,3]). cbind(c(1,3,5), c(2,1,3)) would obviously look like:
[,1] [,2]
[1,] 1 2
[2,]
2023 May 03
1
Inquiry about the behaviour of subsetting and names in matrices
Thank you for such a quick reply, here are some points that I think might have been missed:
> I would state the question the other way : why are NAs integer indices allowed?
> In my experience, they are sometimes useful but they often delay the detection of bugs. However, due to backward compatibility, this feature cannot be removed. Adding this feature to character indices would worsen the
2009 Jul 24
3
str(data.frame) after subsetting reflects original structure, not subsetted structure?
I find that after subsetting (you may prefer "conditional selection") a data
frame and assigning it to a new object, the str(new object) reflects the
original data frame, not the new one:
A <- rnorm(20)
B <- factor(rep(c("t", "g"), 10))
C <- factor(rep(c("h", "l"), 10))
D <- data.frame(A, B, C)
str(D) # reports correctly
E <-
2003 Jul 15
4
(no subject)
Hi
I got a problem with creating a textfile:
how can I create a textfile, which has a headline like:
#data1
1 2 3 4
5 6 7 8
the problem is, how to bind text and matrix, so that the
"read.table"-function
will ignore the text and read the numbers.
Thank you for help
Michael
--
2
2003 Oct 28
2
proposal for "strict" versions of subsetting operators
I'd like to propose adding "strict" versions of the subsetting operators "[", "[[", and "$" to the R language. These strict versions would be intended for use in programming rather than in interactive use. They do not perform any form of partial string matching or opportunistic simplification such as dimension dropping by default. They allow more
1998 Oct 28
2
W95 and no update from samba shares
Hi,
i have a annoying problem that drives me crazy.
We have set up a Digital/Unix box with samba and the clients (W95) can mount
the shares from this box. On the Unix side we create a textfile which will be
periodically (or not) appended with new data. A Application on the W95 side
reads this file.
The Problem is, that the textfile has new lines, the Application don't see
them !!!
To
2010 Jul 15
1
Very slow subsetting by name
Hi,
I'm subsetting a named vector using character indices.
My vector of indices (or keys) is 10x longer than the vector
I'm subsetting. All my keys are distinct and only 10% of them
are valid (i.e. match a name of the vector being subsetted).
It is surprisingly slow:
x1 <- 1:1000
names(x1) <- paste("a", x1, sep="")
keys <- sample(c(names(x1),
2005 Feb 19
2
I have a odd question...
Hi all.
I am going to do a simple "voting application" for a radiostation.
The idea is to have listeners call in to vote on songs.
What I want to do is to take a phonenumer for each song and present the
result on a simple webpage.
Eg.
To vote on song number one, call 555-1111
To vote on song number two, call 555-2222 etc etc.
When the listener calls in, a playback tells him:
2011 Aug 23
1
subsetting a list of matrices
Hi all,
I have an object that looks (roughly) like the following:
l <- list(a = matrix(rnorm(9), 3), b = matrix(rnorm(9), 3), c =
matrix(rnorm(9), 3))
l$a[3,] <- sample(c("Message 1", "Message 2", "Message 3"))
l$b[3,] <- sample(c("Message 1", "Message 2", "Message 3"))
l$c[3,] <- sample(c("Message 1",
2008 Jan 09
1
Subsetting Method [ Revisited
Hello Everyone:
As usual, thanks in advance for any help.
I was hoping to get some more advice on this question:
I'm trying to write a subsetting routine for an S3 object I've created --
lets call it myObject.
myObject has a few attributes basically of type string and numerics. Its
atomic value is just a vector of ints.
I want to write my own subsetting routine to subset myObject in
2001 Dec 19
1
combine
hello there,
I ` m a newbie in R so please excuse my maybe simple question!
I have several (the number of the files changes) textfiles. Each
textfile contains one column with 3 rows (3 numerical values). I want to
combine each file with another file and create new textfiles which then
contain 2 columns with 3 rows. How can I do this in R? Do I have to
use cbind? How Do I use cbind for my