Displaying 20 results from an estimated 6000 matches similar to: "Binning question (binning rows of a data.frame according to a variable)"
2006 May 08
1
performing functions on variables of different length
I am hoping for some assistance with a problem that has puzzled me.
Immediately below is the error messages I obtained when I tried to perform
two functions.
(A)
tapply(outcome,na.rm=T,grp,mean)
Error in tapply(outcome, na.rm = T, grp, mean) :
arguments must have same length
+++++++++++++++++++++++++++++++++++++++++++++++
(B)
library(nlme)
> anova(lme(outcome ~ grp * time,
2006 Jan 04
5
multiple lowess line in one plot
I'm using this code to plot a smoothed line. These two columns of data
really represent 4 groups and I'd like to plot a separate line for each
group but have them all in the same plot. The R-Docs for lowess do not
seem to indicate some type of "GROUPS=var_name" option. What would be
the syntax for this?
plot(AWGT ~ lipid )
lines(lowess(lipid , AWGT, f=.8))
--
Dean
2010 Sep 03
6
how can I plot bar plots with all the bars (negative and positive) in the same direction????
Dear r-help mailing list,
this seems stupid, but I actually don't find the solution:
if I have a vector of numbers x of length n, ranging, say, from -3 to 4, if I do
barplot (x)
all the values below 0 go downwards, and all the positive values go upward. How can I make them all begin from the minimum pointing upwards?
Thanks!
Gabriele Zoppoli, MD
Ph.D. Fellow, Experimental and Clinical
2004 Jun 16
4
non-linear binning? power-law in R
First, thanks to everyone who helped me get to grips with R in (x)emacs
(I get confused easily). Special thanks to Stephen Eglen for continued
support.
My question is about non-linear binning, or density functions over
distributions governed by a power law ...
y ~ mu*x**lambda # In one of its forms
# (can't find Pareto in the online help)
Looking at the following
2008 May 13
2
Plotting Frequency Distribution in R
Hi,
How can plot a frequency distribution curve for the following data.
V1 V2
1 1 160.54%
2 1 201.59%
3 1 18.45%
4 1 179.03%
5 1 274.37%
6 1 0.00%
7 1 24.52%
8 1 39.17%
9 3 43.72%
10 1 53.06%
11 1 64.97%
12 1 79.84%
13 1 98.08%
14 1 115.32%
15 1 127.96%
16 1 155.38%
17 1 157.25%
18 1 193.17%
19 1 51.53%
20 15 99.32%
21 1 106.86%
22 1 219.44%
2005 Nov 14
2
change some levels of a factor column in data frame according to a condition
Dear R-users,
I am looking for an elegant way to change some levels of a factor column
in data frame according to a condition.
Lets look at the following data frame:
> data.frame(crit1=gl(2,5), crit2=factor(letters[1:10]), x=rnorm(10))
crit1 crit2 x
1 1 a -1.06957692
2 1 b 0.24368402
3 1 c -0.24958322
4 1 d -1.37577955
5 1 e
2017 Nov 22
6
assign NA to rows by test on multiple columns of a data frame
Given this data frame (a simplified, essential reproducible example)
A<-c(8,7,10,1,5)
A_flag<-c(10,0,1,0,2)
B<-c(5,6,2,1,0)
B_flag<-c(12,9,0,5,0)
mydf<-data.frame(A, A_flag, B, B_flag)
# this is my initial df
mydf
I want to get to this final situation
i<-which(mydf$A_flag==0)
mydf$A[i]<-NA
ii<-which(mydf$B_flag==0)
mydf$B[ii]<-NA
2017 Nov 22
1
assign NA to rows by test on multiple columns of a data frame
...well, I don't think this is exactly the expected result (see my post)
to be noted that the columns affected should be "A" and "B"
thanks for the help
max
----- Messaggio originale -----
Da: "Rui Barradas" <ruipbarradas at sapo.pt>
A: "Massimo Bressan" <massimo.bressan at arpa.veneto.it>, "r-help" <r-help at
2017 Nov 22
1
assign NA to rows by test on multiple columns of a data frame
OPS,
Sorry i did not read the post carfully. Mine will not work if you have
zeros on columns A and B.. But you could modify it to work for specific
columns i believe.
EK
On Wed, Nov 22, 2017 at 8:37 AM, Ek Esawi <esawiek at gmail.com> wrote:
> Hi *Massimo,*
>
> *Try this.*
>
> *a <- mydf==0mydf[a] <- NAHTHEK*
>
> On Wed, Nov 22, 2017 at 5:34 AM, Massimo Bressan
2017 Nov 22
0
assign NA to rows by test on multiple columns of a data frame
Hello,
Try the following.
icol <- which(grepl("flag", names(mydf)))
mydf[icol] <- lapply(mydf[icol], function(x){
is.na(x) <- x == 0
x
})
mydf
# A A_flag B B_flag
#1 8 10 5 12
#2 7 NA 6 9
#3 10 1 2 NA
#4 1 NA 1 5
#5 5 2 0 NA
Hope this helps,
Rui Barradas
On 11/22/2017 10:34 AM, Massimo Bressan
2017 Nov 23
1
assign NA to rows by test on multiple columns of a data frame
yes, it works, even if I do not really get how and why it's working the combination of logical results (could you provide some insights for that?)
moreover, and most of all, I was hoping for a compact solution because I need to deal with MANY columns (more than 40) in data frame with the same basic structure as the simplified example I posted
thanks
m
----- Messaggio originale -----
Da:
2007 May 17
2
How to select specific rows from a data frame based on values
Dear Group:
I am working with a data frame containing 316 rows of individuals
with 79 variables. Each of these 79 variables have values that range
between -4 to +4, and I want to subset this data frame so that in the
resulting new dataframe, values of _all_ of these variables should
range between -3 and +3.
Let's say I have the following dataframe (it's a toy example with 4
individuals
2017 Nov 22
0
assign NA to rows by test on multiple columns of a data frame
Do you mean like this:
mydf <- within(mydf, {
is.na(A)<- !A_flag
is.na(B)<- !B_flag
}
)
> mydf
A A_flag B B_flag
1 8 10 5 12
2 NA 0 6 9
3 10 1 NA 0
4 NA 0 1 5
5 5 2 NA 0
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into
2010 Feb 15
4
Separating columns, and sorting by rows
Dear anyone who knows more about R than me (so everyone). I have been bashing
my head on the keyboard all day trying to do something with my table.
I have some data, like so:
yyyy-mm Rainfall(mm)
1 1977-02 17.4
2 1977-03 34.0
3 1977-04 26.2
4 1977-05 42.6
5 1977-06 58.6
6 1977-07 23.2
7 1977-08 26.8
8 1977-09 48.4
9
2017 Nov 22
0
assign NA to rows by test on multiple columns of a data frame
Hi *Massimo,*
*Try this.*
*a <- mydf==0mydf[a] <- NAHTHEK*
On Wed, Nov 22, 2017 at 5:34 AM, Massimo Bressan <
massimo.bressan at arpa.veneto.it> wrote:
>
>
> Given this data frame (a simplified, essential reproducible example)
>
>
>
>
> A<-c(8,7,10,1,5)
>
> A_flag<-c(10,0,1,0,2)
>
> B<-c(5,6,2,1,0)
>
> B_flag<-c(12,9,0,5,0)
>
2008 May 08
2
Replicating Rows
Hi,
I have a data matrix in which there are 1000 rows by 30 columns. The first
column of each row is a numeric indicating the number of trips taken to a
particular location with location attributes in the following column entries for
that row.
I want to repeat each row based on the number of trips taken (as indicated by
the number in the first column)...i.e., if 1,1 indicates 4 trips, I want
2005 Apr 26
2
Flip rows and columns of a table?
Any simple way to take a (2D) table and 'rotate' it so all the rows become
columns and the columns rows?
I'll wager there is a simple way ;) - but I can't find it :(
2008 Jul 06
3
Lots of huge matrices, for-loops, speed
Hello,
we have 80 text files with matrices. Each matrix represents a map (rows for
latitude and columns for longitude), the 80 maps represent steps in time. In
addition, we have a vector x of length 80. We would like to compute a
regression between matrices (response through time) and x and create maps
representing coefficients, r2 etc. Problem: the 80 matrices are of the size
4000 x 3500 and we
2009 Dec 23
1
removing rows with NAs in anywere
Dear all,
I have a data.frame with some NAs that can
happens anywere, and I would like to keep
only rows without NAs. Thanks in advance
for your help, and Merry Xmas.
myvect<-runif(100)
myvect[sample(1:100)[1:5]]<-NA
myDF<-data.frame(matrix(myvect,ncol=5))
myDF
miltinho
[[alternative HTML version deleted]]
2010 Jul 14
1
rows process in DF
I have the following datasets:
id d1 d2 d3 d4 d5 d6 d7 d8
1 100 0.3 0.4 -0.2 -0.3 0.5 0.6 -0.9 -0.8
2 101 0.3 0.4 0.5 0.6 -0.2 -0.4 -0.5 -0.6
what I am trying to accomplish:
loop through the rows && do the following:
if the values from the columns of the current row >0 then
sum_positive=total
if the values from the columns of the current row <0 then