[R] Help with sub-setting

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Mon May 25 20:27:27 CEST 2020


Hello,

Inline.

Às 13:26 de 25/05/20, Burgess, Jamie escreveu:
> Dear all,
> 
> I hope this message finds you well. I am currently trying to subset my data by two variables, so far, I have tried two different ways to stratify participants into groups. 

I don't understand what you mean by this, do you want to split the data 
set into sub-dataframes by 2 variables? If so try

df_groups <- split(data, list(data$Var1, data$Var2), drop = TRUE)


This produces a list of sub-df's.
To get the group with Var1 == 1 and Var2 == 1

grp_name <- paste(1, 1, sep = '.')
df_groups[[grp_name]]


But if you only want the sub-df with Var1 == 1 and Var2 == 1, any of the 
following will do it.

data[data$Var1 == 1 & data$Var2 == 1, ]

subset(data, Var1 == 1 & Var2 == 1)


Hope this helps,

Rui Barradas


I would like to use the �summary� and �table� arguments to characterise 
the data of participants based on the presence of two variables and 
summarise this sub-set against a third variable.
> I have used this method:
> 
> dgb001<-subset(data,data$variable==1 & data,data$variable)
> 
> 
> However, I get the following error: �Error: cannot allocate vector of size 16.0 Gb�. Is there another method I can try?
> 
> 
> Kind regards,
> 
> 
> Jamie Burgess
> 
> PhD Student Endocrinology and Diabetes
> 
> University of Liverpool
> 
> Aintree University Hospital &
> 
> The Walton Centre
> 
> Institute of Ageing & Chronic Disease
> 
> 0151 529 5936
> 
> 
> 	[[alternative HTML version deleted]]
> 
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list