hi all
I have this dataframe (created as a reproducible example)
mydf<-structure(list(date_time = structure(c(1508238000, 1508238000,
1508238000, 1508238000, 1508238000, 1508238000, 1508238000), class =
c("POSIXct", "POSIXt"), tzone = ""),
direction = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L),
fferent approach much appreciated
thanks
Da: "Massimo Bressan"
A: "r-help"
Inviato: Giovedì, 9 novembre 2017 12:20:52
Oggetto: weighted average grouped by variables
hi all
I have this dataframe (created as a reproducible example)
mydf<-structure(list
hi thierry
thanks for your reply
yes, you are right, your solution is more straightforward
best
Da: "Thierry Onkelinx"
A: "Massimo Bressan"
Cc: "r-help"
Inviato: Giovedì, 9 novembre 2017 15:17:31
Oggetto: Re: [R] weighted average grouped by variab
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(myd
...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"
A: "Massimo Bressan" , "r-hel
same basic
structure as the simplified example I posted
thanks
m
- Messaggio originale -
Da: "Bert Gunter"
A: "Massimo Bressan"
Cc: "r-help"
Inviato: Mercoledì, 22 novembre 2017 17:32:33
Oggetto: Re: [R] assign NA to rows by test on multiple columns of
#given the following reproducible and simplified example
t<-data.frame(id=1:10,A=c(123,345,123,678,345,123,789,345,123,789))
t
#I need to get the following result
r<-data.frame(unique_A=c(123, 345, 678,
789),list_id=c('1,3,6,9','2,5,8','4','7,10'))
r
# i.e. aggregate over the variable "A
lt;-cbind(unique_A=row.names(r),r)
row.names(r)<-NULL
r
best
Da: "Massimo Bressan"
A: "r-help"
Inviato: Mercoledì, 6 giugno 2018 10:13:10
Oggetto: aggregate and list elements of variables in data.frame
#given the following reproducib
t;-data.frame(id=c(18,91,20,68,54,27,26,15,4,97),A=c(123,345,123,678,345,123,789,345,123,789))
t
# I need to get this result
r<-data.frame(unique_A=c(123, 345, 678,
789),list_id=c('18,20,27,4','91,54,15','68','26,97'))
r
# any help for this, please?
Da: &quo
vals<- lapply(idx, function(index) x$id[index])
data.frame(unique_A = uA, list_vals=unlist(lapply(vals, paste, collapse = ",
")))
best
Da: "Ben Tupper"
A: "Massimo Bressan"
Cc: "r-help"
Inviato: Giovedì, 7 giugno 2018 14:47:55
Oggetto: Re: [
#ok, finally this is my final "best and more compact" solution of the problem
by merging different contributions (thanks to all indeed)
t<-data.frame(id=c(18,91,20,68,54,27,26,15,4,97),A=c(123,345,123,678,345,123,789,345,123,789))
l<-sapply(unique(t$A), function(x) t$id[which(t$A==x)])
r<-dat
# considering this data.frame as a reproducible example
d<-data.frame(i=c(1,2,3), s=c('97,98,99','103,105', '118'), stringsAsFactors =
FALSE)
d
#I need to get this final result
r<-data.frame(i=c(1,1,1,2,2,3), s=c(97, 98, 99, 103, 105, 118))
r
#this is my attempt
#number of components for
ALSE)
d
Da: "Bert Gunter"
A: "Massimo Bressan"
Cc: "r-help"
Inviato: Martedì, 12 giugno 2018 16:42:18
Oggetto: Re: [R] extract and re-arrange components of data frame
You mean like this?
> s.new <-with(d, as.numeric(unlist(strsplit(s,","
&
hello
given my reproducible example
#---
date<-seq(ISOdate(2017,1, 1, 0), by="hour", length.out = 48)
v1<-1:48
df<-data.frame(date,v1)
#--
I need to calculate the average of variable v1 at specific hour "endpoints" of
the day: i.e. at hours 6.00 and 22.00 respectively
the desired resu
;-z8[iz8]
z16<-rollapply(z, width=16, FUN=mean, align="right")
iz16<-which(as.numeric(strftime(index(z16), '%H'))==22)
z16<-z16[iz16]
fortify.zoo(z16)
fortify.zoo(z8)
#and then any sort of manipulation with dataframes
bye
- Messaggio originale -
Da: &quo
by considering the following reproducible example:
v0<-c("a","xxx","c",rep("xxx",2))
v1<-c(1,"b",3,"d","e")
v2<-c(6,2,8,4,5)
v3<-c("xxx",7,"xxx",9,10)
df_start<-data.frame(v0,v1,v2,v3)
df_start
v0<-letters[1:5]
v1<-1:5
v2<-6:10
df_end<-data.frame(v0,v1,v2)
df_end
I need to shift by one colum
please consider the following example:
#start code
set.seed(123)
level<-rnorm(18, 10,3)
group1<-rep(letters[1:3], each=6)
summary(aov(level~group1))
group2<-rep(1:3,each=6)
str(group2)
summary(aov(level~group2))
#same result as for group1
summary(aov(level~factor(group2)))
#same result ad fo
this might be a trivial question (eventually sorry for that!) but I definitely
can not catch the problem here...
please consider the following reproducible example: why of different results
through 'split-lapply' vs. 'aggregate'?
I've been also through a check against different methods (e.g. d
hi
I need to apply a user defined formula over some selected columns of a
dataframe by subsetting group of rows (blocks) and get back a new dataframe
I’ve been managed to get the the calculations right but I’m not satisfied at
all by the form of the results
please refer to my reproducible e
yes, thanks
you pointed me in the right direction: split/unplist was the trick
I completely left behind that possibility!
here the final version
mynorm <- function(x) {(x - min(x, na.rm=TRUE))/(max(x, na.rm=TRUE) - min(x,
na.rm=TRUE))}
mydf<-data.frame(blocks=rep(c("a","b","c"
mydf, b)
l <- lapply(l, transform, v1.mod = mynorm(v1))
mydf_new <- unsplit(l, b)
# 3 - ave() encapsulating split-lapply-unsplit approach
mydf_new<-transform(mydf, v1.mod = ave(v1, blocks, FUN=mynorm))
#
Da: "William Dunlap"
A: "Massimo Bressan"
Cc: "
consider this reproducible example
# set the origin of the grid # in cartesian coordinates (epsg 32632)
xmin<-742966
ymin<-5037923
# set x and y axis
x<-seq(xmin, xmin+25*39, by=25)
y<-seq(ymin, ymin+25*39, by =25)
# define a 40 x 40 grid
mygrid<-expand.grid(x = x, y = y)
# set the z value to be i
given this reproucible example
library(coin)
independence_test(asat ~ group, data = asat, ## exact null distribution
distribution = "exact")
I'm wondering why the default results are reporting also the critical value
Z by considering that this method is supposed to be "exact", i.e. computing
the
thanks jim,
I had to move the legend to a different place (as the default) because
for some reasons it appeared to me "sliced" on the left side (but I'm
not sure if that was due to my own configuration, anyway...); I think
that the possibility to control the size of the point labels would be a
thank you for the help, bert
unfortunately, for reasons I can not understand (yet) I can not put to
wortk it all
(I'm always in trouble with the panel functions);
max
Il 14/09/2012 18:38, Bert Gunter ha scritto:
Thanks for the example. Makes it easy to see what you mean.
Yes, if I understan
ok, I see now!
here it is the reproducible example along with the final code (aslo with
the median line instead of a point)
thank you all for the great help
max
# start code
library(lattice)
test<-structure(list(site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
thank you all for your helpful replies
to bert
the problem with relation ="same" is the plotting along y axis of all
categories ("samp.time") for all groups ("sites"); instead, I need to
plot along y axis just the categories for each group effectively having
a corresponding observation
to dann
deepayan, is that what you mean?
but still the problem persists: nor correct neither contiguous labelling!
I must probably reconsider everything from scratch: I'm bit confused now...
test$samp.time.new <- with(test, reorder(samp.time:site, as.numeric(site)))
s<-strsplit(levels(test$samp.time.new
given this reproducible example:
#start code
df<-structure(list(lq = c(TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE,
FALSE, FALSE), value = c(1, 3, 1, 2, 0.5, 2, 1, 2, 3), group =
structure(c(1L, 1L, 2L, 2L, 3L, 3L, 3L, 1L, 2L), .Label = c("A", "B",
"C"), class = "factor")), .Names = c("lq", "v
thanks rui, it helps indeed..
at first, I've been trying to data.frame the output of mean (mycenfit)
by the following:
my.df<-as.data.frame(do.call(rbind, mean(mycenfit)))
and it worked out correctly!
...but because I also needed the information about "n" and "n.cen",
which are not provided b
I have this dataframe:
df<-structure(list(date = structure(c(1395874800, 1395874800, 1395874800,
1395874800, 1395874800), class = c("POSIXct", "POSIXt"), tzone = ""),
hour = structure(c(-2209121804, -2209121567, -2209121005,
-2209118616, -2209116160), class = c("POSIXct", "POSIXt"), tzon
ad in and convert the data yourself, or is this a
> source that
> > you do not have any control over? If the former, then just use the
> > correct
> > conversion. As shown below, if you have hundredths of a second,
> that will
> > be converted correctly and y
given this "bare bone" example:
df1 <- data.frame(id=rep(1:3,each=2), item=c(rep("A",2), rep("B",2),
rep("C",2)))
df2 <- data.frame(id=c(1,2,3), who=c("tizio","caio","sempronio"))
I need to group the first dataframe "df1" by "id" and then merge with
the second dataframe "df2" (again by "id")
in doubt wheter I must open another thread or keep going with
this one (really sorry for the eventual violation of the R-help netiquette)
Il 08/05/2014 17:14, arun ha scritto:
Hi,
May be this helps:
merge(unique(df1),df2)
A.K.
On Thursday, May 8, 2014 5:46 AM, Massimo Bressan
wrote:
given
/2014 18:43, arun ha scritto:
Hi,
May be:
indx <- !duplicated(as.character(interaction(df1[,-3])))
merge(df1[indx,],df2)
A.K.
On Thursday, May 8, 2014 12:34 PM, Massimo Bressan
wrote:
yes, thank you for all your replies, they worked out correctly indeed...
...but because of my fault, by t
#let's suppose I have a list like this
mytest<-list(45, NULL, 18, NULL, 99)
#to note that this is just an amended example because in fact
#I'm dealing with a long list (more than 400 elements)
#with no evident pattern of the NULL values
#I want to end up with a data frame like the following
d
(45, NA, 18, NA, 99)
(The NULLS must be converted to NA's to "hold" their places).
There would then seem to be little need for the data frame structure,
as it tends to slow things down in R. But if you insist,
which(is.na(y))
will give you the indices of the NA's.
See also: ?is
ect.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Massimo
Bressan
Sent: Thursday, October 3, 2013 9:42 AM
To: r-help@r-project.org
Subject: [R] storing element number of a list in a column data
frame
#let's suppose I have a list like this
mytest<-list(45, NULL, 18, NULL, 99)
#to note th
Given this general example:
set.seed(1)
data(iris)
iris.rf <- randomForest(Species ~ ., iris, proximity=TRUE, keep.forest=TRUE)
#varImpPlot(iris.rf)
#varUsed(iris.rf)
MDSplot(iris.rf, iris$Species)
I’ve been reading the documentation about random forest (at best of my -
poor - knowledge) b
f the intention anyway. One can also use them to do
clustering.
Best,
Andy
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Massimo Bressan
Sent: Monday, December 02, 2013 6:34 AM
To: r-help@r-project.org
Subject: [R] interpretation of MD
by considering this general example
##start code
library(ipred)
data("Ionosphere", package = "mlbench")
Ionosphere$V2 <- NULL # constant within groups
iono<-bagging(Class ~ ., data=Ionosphere, coob=TRUE)
print(iono)
##end code
does anybody knows any possibility to plot the (average) plot of th
yes, the argument "labels" it's working fine!
It would be great if the docs will be be updated also with this already
implemented feature
thank you for your valuable work
best
max
Il 13/08/2012 15:09, Uwe Ligges ha scritto:
On 13.08.2012 12:12, maxbre wrote:
given this example
library(c
I tested your code: it's OK but there is still the problem of the suffixes
for the last dataframe
thank you for the support
- Original Message -
From: "R. Michael Weylandt"
To: "maxbre"
Cc:
Sent: Thursday, January 26, 2012 8:19 PM
Subject: Re: [R] merge multiple data frames
I
hi don
I followed your advice about using sqldf package but the problem of
labelling the fields persists;
for some reasons I can not properly handle the sql 'as' statement
a_b<-sqldf("select a.*, b.* from a left join b on a.date=b.date")
a_b_c<-sqldf("select a_b.*, c.* from a_b left join c
thanks michael
it's working like a charm: that's exaclty what I was looking for
bye
max
- Original Message -
From: "R. Michael Weylandt"
To: "Massimo Bressan"
Cc:
Sent: Friday, January 27, 2012 4:16 PM
Subject: Re: [R] merge multiple data frames
O
thanks don
I have here enough to study for a while
thank you for your help
max
- Original Message -
From: "MacQueen, Don"
To: "Massimo Bressan" ;
Sent: Monday, January 30, 2012 4:47 PM
Subject: Re: [R] merge multiple data frames
Does this example help? I
46 matches
Mail list logo