Displaying 20 results from an estimated 20000 matches similar to: "subset by multiple columns satisfying the same condition"
2008 Mar 08
1
Deleting rows satisfying a certain condition (sum of some colums>2)
I have a huge matrix and need to delete certain rows. What I need to do is:
1.In each row, calculate the sum of jth column and (J+2)th column
2. If the sum is greater than 2 then that row needs to be deleted.
I have a sample matrix and my codes here. It does remove some rows but when
it does, it skips the next row and each time it deletes a row, the dimension
changes so it gets out of bound. I
2004 Jul 19
10
How to compare X1 = X2 = ... = Xn?
Dear All,
I have a data frame with n columns: X1, X2, ., Xn. Now I want to create a
new column: if X1 = X2 = . = Xn, the value is 1; Otherwise, the value is 0.
How to do that in a quick way instead of doing (n choose 2) comparisons?
Thank you,
Frank
[[alternative HTML version deleted]]
2004 Jul 06
2
Generate a matrix Q satisfying t(Q)%*%Q=Z and XQ=W
Hello,
I have a question that is not directly related to R ... but I try to do it
in R ;-) :
I would like to generate a matrix Q satisfying (for a given Z, X and W) the
two following conditions:
t(Q)%*%Q=Z (1)
XQ=W (2)
where:
Q is m rows and r columns
X is p rows and m columns
D is p rows and r columns
C is r rows and r columns
with m>p,r
e.g:
m=6,
p=2
r=3
2010 Mar 29
1
Suggestion: Adding quick rowMin and rowMax functions to base package
Hi,
I wonder whether similarly to the very quick rowSums and colSums
functions in the base package, one could add quick functions that
calculate the min or max over rows / cols in a matrix. While
apply(x,1,min) works, I found out by profiling a program of mine that it
is rather slow for matrices with a very large number of rows. A quick
functionality seems to be already there in the
2004 Nov 18
5
How to calculate the stratified means in a data frame?
Dear R people,
I have a simple question to ask. Suppose I have a data.frame with two
variables: one factor (x) and one numeric (y), I want to calculate the
mean of y for each value of x. Although it's easy to do it within a
for a loop, I believe there may be a concise way by using some kinds
of "apply" functions. Could anyone tell me how to do that? Thank you.
Frank
2012 Oct 30
4
There is pmin and pmax each taking na.rm, how about psum?
Hi,
Please consider the following :
x = c(1,3,NA,5)
y = c(2,NA,4,1)
min(x,y,na.rm=TRUE) # ok
[1] 1
max(x,y,na.rm=TRUE) # ok
[1] 5
sum(x,y,na.rm=TRUE) # ok
[1] 16
pmin(x,y,na.rm=TRUE) # ok
[1] 1 3 4 1
pmax(x,y,na.rm=TRUE) # ok
[1] 2 3 4 5
psum(x,y,na.rm=TRUE)
[1] 3 3 4 6 # expected result
Error: could not find function "psum" # actual result
2006 Sep 13
7
inserting columns in the middle of a dataframe
Dear R users:
Is there a built-in and simple way to insert new columns after other columns
in a dataframe?
I.e. currently I have:
V1 V2 V3 V4
[1,]
[2,]
Etc.
But I want
V1 V5 V2 V3 V4
[1,]
[2,]
Etc.
Can this be done in one line?
Jon Minton
[[alternative HTML version deleted]]
2002 Dec 12
4
sum a list of vectors
In Mathematica there is a neat feature, where you can change the head of a list from "list" to say "+" and obtain a sum of the list elements.
I can't find a way to sum a list of vectors of same length or list of matrices of the same dimension and was curious if something like that exists in R. do.call("+",list) doesn't work because "+" accepts only
2006 Sep 25
2
Splitting a character variable into a numeric one and a character one?
Hi All,
I have a data with a variable like this:
Column 1
"123abc"
"12cd34"
"1e23"
...
Now I want to do an operation that can split it into two variables:
Column 1 Column 2 Column 3
"123abc" 123 "abc"
"12cd34" 12 "cd34"
"1e23" 1
2008 Apr 27
1
parallel max, min, and median of dataframe columns
Hello, all,
I have a dataframe of three rows and umpteen columns. I want to show the
maximum, minimum, and median with a vertical line and a central dot (I'd
use a boxplot, but with only three data points, that's overkill; I can't
just use points, because of overlap and some of the other data plotted on
the graph).
This works:
> boxplot(data_frame,
2009 Jun 30
2
Using functions to change values in a data.frame
I'm having trouble with something that looks easy. (And I'm sure it
will be easier within about 1 minute of receiving my first response.)
Thanks in advance.
I have a collection of data frames that I need to add columns, do some
calculations and then fill in the new columns. Since I have a large
number of similar data frames I want to do this with functions to make
the code more readable
2009 Jul 01
2
?max (so far...)
Hi,
I have a data.frame that is date ordered by row number - earliest
date first and most current last. I want to create a couple of new
columns that show the max and min values from other columns *so far* -
not for the whole data.frame.
It seems this sort of question is really coming from my lack of
understanding about how R intends me to limit myself to portions of a
data.frame. I get the
2009 Jul 01
1
running count in data.frame
Hi,
I need to keep a running count of events that have happened in my
data.frame. I found a document called usingR that had an example of
doing this for random coin flips and I tried to modify it. It seems to
sort of work in the beginning, but then it stops and I don't
understand why. I'm trying to duplicate essentially the Excel
capability of =SUM($A$1:$A(Row number))
The example
2018 Mar 26
2
R Lapack – why a subset?
Hi,
Why doesn't R include a full Lapack but only a subset?
My cda package (now archived) relying on RcppArmadillo has broken multiple
times on CRAN over the past few years following updates in the underlying
Armadillo library, Every time it follows the same pattern: Armadillo adds a
function to solve a specialised linear system more efficiently, and the
corresponding Lapack routine is not
2010 May 19
1
export dataframe's column classes to a list
Hi Folks,
I want to export a dataframe's column classes to a list so that I can
reinstantiate the dataframe from a CSV file in the future. (I know
about save(), which I'm using in addition to this).
what I want to do is the following:
write.csv(myframe);
col_classes = get_col_classes(myframe);
write.csv(col_classes, "column_classes")
... time passes, R gets
2012 Nov 09
3
if between 500-600 give 550
I have a data frame somewhat like this:
myframe <- data.frame (ID=c(2,3,4,5), Hunger =c(415,452,550,318 ))
myframe
Now I would like to add a column to the right which summarizes the values
for Hunger somewhat to reduce the number of values: If the values for Hunger
are between
300-400 I would like to insert the number 350,
between
400-500 insert 450
between
500-600 insert 550
Does
2012 Sep 26
2
average environmental data if AnimalID and Time is duplicated
Hello,
I tried for about three hours now to solve this problem but I can't figure
it out. I am sure someone knows how do it. At least I hope so.
I have a data frame somewhat like this:
myframe <- data.frame (ID=c("Ernie", "Ernie", "Bert", "Bert"),
Timestamp=c("24.09.2012 09:00", "24.09.2012 09:00", "24.09.2012 10:00",
2004 Aug 09
5
How to import specific column(s) using "read.table"?
Dear R people,
I have a very big tab-delim txt file with header and I only want to import
several columns into R. I checked the options for "read.table" and only
found "nrows" which lets you specify the maximum number of rows to read in.
Although I can use some text editors (e.g., wordpad) to edit the txt file first
before running R, I feel it?s not very convenient. The
2010 Mar 05
2
Selecting rows of a matrix based on some condition on the columns
The data set consists of two sets of matrices, as labelled by the columns, T's and C's.
> xy
x T1 T2 T3 T4 T5 C1 C2 C3 C4 C5
[1,] 50 0.00 0.00 33.75 0.00 0.00 0.00 36.76 0.00 35.26 0.00
[2,] 13 34.41 0.00 0.00 36.64 32.86 34.11 35.80 37.74 0.00 0.00
[3,] 14 35.85 0.00 33.88 36.68 34.88 34.58 0.00 32.75 37.45 0.00
[4,] 33 34.56
2010 Feb 21
1
Comparing two date columns
Hi everyone,
I have another fairly simple question. I want to take the earliest of two
dates from these two date columns. I've tried converting the dates to
numbers and just get a vector full of NA's. I've also tried using the chron
function to compare the two and have been unsuccessful. I then tried to
use:temp.2 <- as.POSIXct(strptime(temp, '%d/%m/%Y')) where temp is