[R] pheatmap - clustering of select columns

2019-03-08 Thread Adrian Johnson
Dear group,
In pheatmap, is it possible to cluster select colmns.
For example, in a matrix of 10 rows and 20 columns. I want to cluster
only those columns 1-10 and cluster rows. Similarly, retaining the
same row clustering resulted from clustering of columns 1-10, I want
to enforce clustering of 11-20 and not clustering rows.
Is it possible. Currently I use cluster_cols=TRUE, but this clusters
all columns.
Thanks for your help

Adrian.

__
R-help@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.


Re: [R] Common elements

2019-03-08 Thread Rui Barradas

Hello,

If I understand correctly, here are two different ways of doing what you 
want.


1) base R.

i <- duplicated(df1[[2]])
j <- duplicated(df1[[2]], fromLast = TRUE)
res <- df1[i | j, ]

res[order(res[[2]]), ]# not strictly needed


2) with package dplyr. If you do not want to order by Mother,
delete the last %>%, at the end of the line and the next line, 
arrange(Mother).


library(dplyr)

df1 %>% group_by(Mother) %>% filter(n() > 1) %>%
  arrange(Mother)


# dataset --
# Note that your data seems to be a matrix,
# read.table creates data.frames

df1 <- read.table(text = "
  Animal Mother
[1,]   1143430
[2,]   1144134
[3,]   1146  3
[4,]   1147151
[5,]   1150230
[6,]   1156290
[7,]   1157227
[8,]   1159757
[9,]   1160  3
[10,]   1161236
[11,]   1162231
[12,]   1164132
[13,]   1165420
[14,]   1168290
[15,]   1169229
[16,]   1172425
[17,]   1173134
[18,]   1174234
[19,]   1175233
[20,]   1178239
[21,]   1179757
[22,]   1180236
[23,]   1185420
[24,]   1186389
[25,]   1190425
[26,]   1192235
", header = TRUE)
row.names(df1) <- NULL



Hope this helps,

Rui Barradas


Às 17:51 de 08/03/2019, Silvano Cesar da Costa escreveu:

Hi,

I have a dataset with ten columns, but I need extract only lines that has
common elements.
The columns are:

   Animal Mother
  [1,]   1143430
  [2,]   1144134
  [3,]   1146  3
  [4,]   1147151
  [5,]   1150230
  [6,]   1156290
  [7,]   1157227
  [8,]   1159757
  [9,]   1160  3
[10,]   1161236
[11,]   1162231
[12,]   1164132
[13,]   1165420
[14,]   1168290
[15,]   1169229
[16,]   1172425
[17,]   1173134
[18,]   1174234
[19,]   1175233
[20,]   1178239
[21,]   1179757
[22,]   1180236
[23,]   1185420
[24,]   1186389
[25,]   1190425
[26,]   1192235

How can I do this?

Thanks.

Prof. Dr. Silvano Cesar da Costa
Universidade Estadual de Londrina
Centro de Ciências Exatas
Departamento de Estatística

Fone: (43) 3371-4346

[[alternative HTML version deleted]]

__
R-help@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.



__
R-help@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.


Re: [R] Common elements

2019-03-08 Thread Doran, Harold
Do you mean like this?

tmp <- data.frame(v1 = c(1,2,1,4,2), v2 = c(10, 11, 10, 14, 11))
vals <- paste(tmp$v1, tmp$v2, sep ='')
tmp[which(vals %in% vals[duplicated(vals)]),]



On 3/8/19, 12:51 PM, "Silvano Cesar da Costa"  wrote:

>Hi,
>
>I have a dataset with ten columns, but I need extract only lines that has
>common elements.
>The columns are:
>
>  Animal Mother
> [1,]   1143430
> [2,]   1144134
> [3,]   1146  3
> [4,]   1147151
> [5,]   1150230
> [6,]   1156290
> [7,]   1157227
> [8,]   1159757
> [9,]   1160  3
>[10,]   1161236
>[11,]   1162231
>[12,]   1164132
>[13,]   1165420
>[14,]   1168290
>[15,]   1169229
>[16,]   1172425
>[17,]   1173134
>[18,]   1174234
>[19,]   1175233
>[20,]   1178239
>[21,]   1179757
>[22,]   1180236
>[23,]   1185420
>[24,]   1186389
>[25,]   1190425
>[26,]   1192235
>
>How can I do this?
>
>Thanks.
>
>Prof. Dr. Silvano Cesar da Costa
>Universidade Estadual de Londrina
>Centro de Ciências Exatas
>Departamento de Estatística
>
>Fone: (43) 3371-4346
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@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.
>

__
R-help@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.


Re: [R] Common elements

2019-03-08 Thread Jeff Newmiller
This request is quite unclear. Can you make a reproducible example [1][2][3] 
and provide data that represents the expected result corresponding to the input 
data? The dput function is much much better than tabular form for this purpose.

For one thing, you mention ten columns, but they are not shown?

[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

[3] https://cran.r-project.org/web/packages/reprex/index.html (read the 
vignette)

On March 8, 2019 9:51:20 AM PST, Silvano Cesar da Costa  wrote:
>Hi,
>
>I have a dataset with ten columns, but I need extract only lines that
>has
>common elements.
>The columns are:
>
>  Animal Mother
> [1,]   1143430
> [2,]   1144134
> [3,]   1146  3
> [4,]   1147151
> [5,]   1150230
> [6,]   1156290
> [7,]   1157227
> [8,]   1159757
> [9,]   1160  3
>[10,]   1161236
>[11,]   1162231
>[12,]   1164132
>[13,]   1165420
>[14,]   1168290
>[15,]   1169229
>[16,]   1172425
>[17,]   1173134
>[18,]   1174234
>[19,]   1175233
>[20,]   1178239
>[21,]   1179757
>[22,]   1180236
>[23,]   1185420
>[24,]   1186389
>[25,]   1190425
>[26,]   1192235
>
>How can I do this?
>
>Thanks.
>
>Prof. Dr. Silvano Cesar da Costa
>Universidade Estadual de Londrina
>Centro de Ciências Exatas
>Departamento de Estatística
>
>Fone: (43) 3371-4346
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@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.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@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.


[R] Common elements

2019-03-08 Thread Silvano Cesar da Costa
Hi,

I have a dataset with ten columns, but I need extract only lines that has
common elements.
The columns are:

  Animal Mother
 [1,]   1143430
 [2,]   1144134
 [3,]   1146  3
 [4,]   1147151
 [5,]   1150230
 [6,]   1156290
 [7,]   1157227
 [8,]   1159757
 [9,]   1160  3
[10,]   1161236
[11,]   1162231
[12,]   1164132
[13,]   1165420
[14,]   1168290
[15,]   1169229
[16,]   1172425
[17,]   1173134
[18,]   1174234
[19,]   1175233
[20,]   1178239
[21,]   1179757
[22,]   1180236
[23,]   1185420
[24,]   1186389
[25,]   1190425
[26,]   1192235

How can I do this?

Thanks.

Prof. Dr. Silvano Cesar da Costa
Universidade Estadual de Londrina
Centro de Ciências Exatas
Departamento de Estatística

Fone: (43) 3371-4346

[[alternative HTML version deleted]]

__
R-help@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.


[R-es] Partial Dependence Plots

2019-03-08 Thread Manuel Mendoza



Buenas tardes erreros, tras aplicar randomForest, aplico partialPlots  
¿sabéis como estandarizar los PDPs de las distintas variables (para  
poder comparar sus efectos), o que me los represente para un mismo  
rango de y? Me parece recordar haberlo visto, pero en la documentacion  
de randomForest no lo encuentro.

Gracias, como siempre,
Manuel




































.
--
Dr Manuel Mendoza
Department of Biogeography and Global Change
National Museum of Natural Science (MNCN)
Spanish Scientific Council (CSIC)
C/ Serrano 115bis, 28006 MADRID
Spain

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] rounding off problem.....

2019-03-08 Thread Kevin Thorpe
I'm no expert in R internals or floating point computation, however, two things 
come to mind.

First, I suspect the exact value is stored. It is just the printing that looks 
rounded. That is likely because 0.001 completely dominates the rest. To print 
in full precision, you would need over 200 digits for some of your values.

Second, you may be pushing the limits of precision. It seems to me your 
original values are indistinguishable from zero. If they really represent 
materially different values, you might want to rescale them to improve 
computational reliability. 

-- 
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: kevin.tho...@utoronto.ca  Tel: 416.864.5776  Fax: 416.864.3016
 

On 2019-03-08, 7:39 AM, "R-help on behalf of akshay kulkarni" 
 wrote:

dear members
 here is a piece of my code:

> tail(YLf14,15)
 [1] 5.706871e-217 2.563877e-218 2.823295e-218 2.694622e-222 1.777409e-226
 [6] 1.134403e-201 5.269464e-215 2.272121e-219 2.794970e-223 1.630978e-187
[11] 1.721529e-213 5.859815e-178 4.842612e-222 1.333685e-193 1.256051e-174
> YLf16 <- YLf14 + 0.001
> tail(YLf16,15)
 [1] 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
[13] 0.001 0.001 0.001

Is there any way to avoid the rounding off of YLf16 to 0.001, and take 
exact values?

very many thanks for your time and effort..
yours sincerely,
AKSHAY M KULKARNI


[[alternative HTML version deleted]]

__
R-help@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.


__
R-help@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.


Re: [R] rounding off problem.....

2019-03-08 Thread Eric Berger
"Is there any way ..."
Two quick answers:
1. using base R functions and data types the answer is 'no' - a double
(i.e. numeric) contains about 15 significant digits.
So 5.678e-100 is fine but   0.01 + 5.678e-100 will keep the
.0100  as the significant digits and "drop" the digits 80 or so
places further to the right.
2. there are packages that provide for arbitrary precision calculations
see R CRAN package Rmpfr
 https://cran.r-project.org/web/packages/Rmpfr/vignettes/Rmpfr-pkg.pdf

HTH,
Eric

On Fri, Mar 8, 2019 at 2:39 PM akshay kulkarni 
wrote:

> dear members
>  here is a piece of my code:
>
> > tail(YLf14,15)
>  [1] 5.706871e-217 2.563877e-218 2.823295e-218 2.694622e-222 1.777409e-226
>  [6] 1.134403e-201 5.269464e-215 2.272121e-219 2.794970e-223 1.630978e-187
> [11] 1.721529e-213 5.859815e-178 4.842612e-222 1.333685e-193 1.256051e-174
> > YLf16 <- YLf14 + 0.001
> > tail(YLf16,15)
>  [1] 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
> 0.001
> [13] 0.001 0.001 0.001
>
> Is there any way to avoid the rounding off of YLf16 to 0.001, and take
> exact values?
>
> very many thanks for your time and effort..
> yours sincerely,
> AKSHAY M KULKARNI
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R-es] Crear una variable tipo factor a partir de un vector de caracteres

2019-03-08 Thread Antonio Rodriguez Andres
Aqui adjunto el código que finalmente funcionó, por si alguien pudiera
necesitarlo en el futuro en la lista


func1 <- function(x){
  ifelse(x %in% ca, "Central Africa", ifelse(x %in% ea,"East Africa",
ifelse(x%in% sa, "South Africa", ifelse(x%in% wa, "West Africa",
ifelse(x%in% na, "North Africa", "otros")
}

afdata$region <- func1(afdata$Country)

afdata$region = as.factor(afdata$region)

On Wed, 6 Mar 2019 at 15:44, Carlos J. Gil Bellosta 
wrote:

> Con R base:
>
> paises <- factor(c("a", "b", "c", "c", "a"))
>
> zonas <- c("norte", "norte", "sur")
> names(zonas) <- c("a", "b", "c")
>
> zonas_paises <- paises
> levels(zonas_paises) <- zonas[levels(zonas_paises)]
> zonas_paises
>
> Un saludo,
>
> Carlos J. Gil Bellosta
> http://www.datanalytics.com
>
>
> El mié., 6 mar. 2019 a las 15:41, Xavier-Andoni Tibau Alberdi (<
> xaviti...@gmail.com>) escribió:
>
>> No, No. Fíjate en el Ifelse(condición, valor si positivo, valor si
>> negativo).
>>
>> Si, x %in% ca entonces el valor devuelto es "ca", un factor. En caso
>> negativo, vamos al siguiente bloque iflese, que comprueba si el país esta
>> en el siguiente grupo, na. Si está en na nos devuelve "na". Vamos, que la
>> función mira en que grupo esta ese país y te devuelve una string,
>> correspondiente al país. Así que ahora tienes un factor, con 5 posibles
>> valores ("ca", "na", ..., "ea"). Es lo que quieres no?
>>
>> Xavier Tibau
>>
>> Missatge de Antonio Rodriguez Andres 
>> del dia dc., 6 de març 2019 a les 15:34:
>>
>> > Pero eso es para crear variables binarias tipo 0-1 si el pais pertence a
>> > un determinado grupo. Lo que quiero es crear una variable de tipo factor
>> > con esos 5 niveles, sabiendo que tengo en el dataframe una variable
>> llamada
>> > Country, con el nombre del pais.
>> > Gracias
>> >
>> > On Wed, 6 Mar 2019 at 15:27, Xavier-Andoni Tibau Alberdi <
>> > xaviti...@gmail.com> wrote:
>> >
>> >> Buenas,
>> >>
>> >> Para ello yo uso el operador %in%, que me dice si algo esta dentro de
>> un
>> >> vector. Luego hago bucles de if else, pero usando la función iflese().
>> Si
>> >> país X esta en países lista ca, entonces "ca",etc. Puedes crear una
>> función
>> >> que englobe ese iflese(), para aplicarla para cada columna del
>> dataframe.
>> >>
>> >> Algo así como:
>> >>
>> >> func1 <- func (x) {ifelse(x %in% ca, "ca", ifelse(x %in% na,"na", ...,
>> >> ifelse(x %in% ea, "ea", "otros"))...)}
>> >>
>> >> espero que te sirva!
>> >>
>> >> Xavier Tibau
>> >>
>> >>
>> >>
>> >> Missatge de Antonio Rodriguez Andres <
>> antoniorodriguezandre...@gmail.com>
>> >> del dia dc., 6 de març 2019 a les 15:10:
>> >>
>> >>> Hola estimados miembros de la comunidad de R
>> >>>
>> >>> Tengo un conjunto de datos, donde tengo observaciones por países y por
>> >>> año.
>> >>> Una de las variables del dataframe es el nombre del país. Queremos
>> >>> dividir
>> >>> los países, que son países africanos de acuerdo a 5 regiones: norte de
>> >>> africa, africa del este, sur africa, etc
>> >>>
>> >>> Yo lo que he hecho ha sido crear vectores con el nombre de cada uno de
>> >>> los
>> >>> países en cada uno de ellos, por ejemplo este de Africa Central,
>> >>>
>> >>> ca <- c("Angola", "Cameroon", "Cabo Verde", "Central African
>> Republic",
>> >>> "Chad","Equatorial Guinea", "Eritrea", "Ethiopia",
>> >>> "Gabon", "Sao Tome and Principe")
>> >>> class(ca)
>> >>> character
>> >>>
>> >>> luego hice un ifelse para crear una variable binaria 1 si es pais de
>> >>> Central Africa y cero sino lo es
>> >>>
>> >>> afdata$Country.centralafrica <- ifelse(afdata$Country %in% ca,1,0)
>> >>>
>> >>> Sin embargo, para el análisis podría ser más interesante crear una
>> >>> variable
>> >>> nueva por ejemplo region y tratarla como factor,. Mi pregunta es como
>> >>> podria pasar esos 5 vectores con el nombre de los paises de cada
>> region a
>> >>> una sola variable tratada como un factor y con esos 5 niveles ( 5
>> >>> regiones). Lo que he tratado es de hacer esto para genera una nueva
>> >>> variable en el dataframe, pero me da que todo es igual false, en el
>> >>> valor,
>> >>>
>> >>> afdata$region <- with(afdata,{
>> >>>   (Country == "ca" |Country == "na" | Country == "sa" | Country ==
>> "wa" |
>> >>> Country == "ea")
>> >>> })
>> >>> Debo de indicar otra condición?
>> >>>
>> >>> Agradezco alguna pista
>> >>>
>> >>> --
>> >>>
>> >>> Member, Editorial Committee, *The Economic and Labour Relations
>> Review*
>> >>> (a
>> >>> SAGE journal)
>> >>>
>> >>> http://elr.sagepub.com/
>> >>>
>> >>> Member, Editorial Committee, African Journal of Economic and
>> Management
>> >>> Studies
>> >>>
>> >>>
>> >>>
>> http://emeraldgrouppublishing.com/products/journals/editorial_team.htm?id=ajems
>> >>>
>> >>> https://www.researchgate.net/profile/Antonio_Andres (Research Gate
>> >>> profile)
>> >>>
>> >>> [[alternative HTML version deleted]]
>> >>>
>> >>> ___
>> >>> R-help-es mailing list
>> >>> R-help-es@r-project.org
>> >>>