[R] Keep only those values in a row in a data frame which occur only once.

2017-06-11 Thread Ashim Kapoor
Dear All,

I have a file data.txt as follows:

Name_1,A,B,C
Name_2,E,F
Name_3,I,J,I,K,L,M

I will read this with:
my_data<- read.csv("data.txt",header=FALSE,col.names=paste0("V",
seq(1:10)),fill=TRUE)

Then the file will have 10 columns. I am assuming that each row in data.txt
will have at the max 10 entries.

Note: Here each row will have a different number of columns in data.txt but
each row will have 10 ( some trailing blank columns ) columns.

My query is how can I keep only the unique elements in each row? For
example: I want the row 3 to be Name_3,I,J,K,L,M

Please note I don't want the 2nd I to appear.

How can I do this?

Best Regards,
Ashim

[[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] package ‘rgdal’ is not available (for R version 3.2.3)

2017-06-11 Thread javier valdes
Estimados:

Es posible solucionar este tema?? He probado con varias alternativas disponibles en internet, pero ninguna me ha funcionado aun.

Saludos.

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

[R] Memory leak in nleqslv()

2017-06-11 Thread Andrew Leach
Hello all,

I am relatively new to R, but enjoying it very much.  I am hoping that
someone on this list can help me with an issue I am having.

I am having issues with iterations over nleqslv, in that the solver
does not appear to clean up memory used in previous iterations. I
believe I've isolated the/my issue in a small sample of code:

library(nleqslv)

cons_ext_test <- function(x){
rows_x <- length(x)/2
x_1 <- x[1:rows_x]
x_2 <- x[(rows_x+1):(rows_x*2)]
eq1<- x_1-100
eq2<-x_2*10-40
return(c(eq1,eq2))
}

model_test <- function()
{
reserves<-(c(0:200)/200)^(2)*2000
lambda <- numeric(NROW(reserves))+5
res_ext <- pmin((reserves*.5),5)
x_test <- c(res_ext,lambda)
#print(x_test)
for(test_iter in c(1:1000))
   nleqslv(x_test,cons_ext_test,jacobian=NULL)
i<- sort( sapply(ls(),function(x){object.size(get(x))}))
print(i[(NROW(i)-5):NROW(i)])
}

model_test()

When I run this over 1000 iterations, memory use ramps up to over 2.4 GB

While running it with 10 iterations uses far less memory, only 95MB:

Running it once has my rsession with 62Mb of use, so growth in memory
allocation scales with iterations.

Even after 1000 iterations, with 2+ GB of memory used by the R
session, no large-sized objects are listed, although mem_use() shows
2+ GB of memory used.

test_iterlambda   res_ext  reservesx_test
   48  1648 1648  1648  3256

I've replicated this on OS-X and in Windows both on a desktop and a
Surface Pro, however colleagues have run this on their machines and
not found the same result.  gc() does not rectify the issue, although
re-starting R does.

Any help would be much appreciated.

AJL


-- 
Andrew Leach
Associate Professor of Natural Resources, Energy and Environment (NREE)
Academic Director, Energy Programs
Alberta School of Business| 3-20D Business Building
University of Alberta |Edmonton, AB  T6G 2R6 | Canada
T. 780.492.8489
E. andrew.le...@ualberta.ca
www.business.ualberta.ca

Follow me on Twitter at @andrew_leach

__
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] plspm package error in data frame

2017-06-11 Thread Rui Barradas

Hello,

Your code throws an error before the line you've mentioned:

> library(plspm)
>
> "Attitude" = c(1, 0, 0, 0, 0, 0, 0, 0)
>
> "Normative Beliefs" = c(1, 0, 0, 0, 0, 0, 0, 0)
>
> "Subjective Norm" = c(0, 0, 1, 0, 0, 0, 0, 0)
>
> "Control Beliefs" = c(1, 0, 1, 0, 0, 0, 0, 0)
>
> "Perceived Behavioural Control" = c(0, 0, 0, 0, 1, 0, 0, 0)
>
> "Intention" = c(0, 1, 0, 1, 0, 1, 0, 0)
>
> "Behaviour" = c(0, 0, 0, 0, 0, 0, 1, 0)
>
> TPB_path = rbind(`Behavioural Beliefs`, Attitude, `Normative 
Beliefs`, `Subjective Norm`, `Control Beliefs`, `Perceived Behavioural 
Control`, Intention, Behaviour)
Error in rbind(`Behavioural Beliefs`, Attitude, `Normative Beliefs`, 
`Subjective Norm`,  :

  object 'Behavioural Beliefs' not found


Please correct this error and post what 'Behavioural Beliefs' is.

Hope this helps,

Rui Barradas

Em 11-06-2017 20:16, Sarah Sinasac escreveu:

Hello,
I am new to R and hope I will not seem ignorant in this post. I am
currently using the plspm package by Gaston Sanchez accompanied by his
text book.
I have attempted to create a square matrix, which has seemed
successful. I used the following code:


"Attitude" = c(1, 0, 0, 0, 0, 0, 0, 0)



"Normative Beliefs" = c(1, 0, 0, 0, 0, 0, 0, 0)



"Subjective Norm" = c(0, 0, 1, 0, 0, 0, 0, 0)



"Control Beliefs" = c(1, 0, 1, 0, 0, 0, 0, 0)



"Perceived Behavioural Control" = c(0, 0, 0, 0, 1, 0, 0, 0)



"Intention" = c(0, 1, 0, 1, 0, 1, 0, 0)



"Behaviour" = c(0, 0, 0, 0, 0, 0, 1, 0)



TPB_path = rbind(`Behavioural Beliefs`, Attitude, `Normative Beliefs`, 
`Subjective Norm`, `Control Beliefs`, `Perceived Behavioural Control`, 
Intention, Behaviour)



colnames(TPB_path) = rownames(TPB_path)



innerplot(TPB_path, box.size = 0.1)


Then I attempted to set up the pls model using the following code (as
directed by the textbook and the r help function):


#outermodel



TPB_blocks = list(1:7, 8:14, 15:21, 22:28, 29:34, 35:39, 40:44, 45:48)



TPB_modes = rep("A", 8)



TPB_pls1 = plspm(TPBDATA, TPB_path, TPB_blocks, modes = TPB_modes)


However, I received the following error (I tried multiple times, and
cannot determine what the error is):

Error in `[.data.frame`(crossloadings, , c("name", "block", colnames(xloads))) :

   undefined columns selected


I would really appreciate if anyone could provide advice on how to
correct this error. I am using the plspm package in order to analyze
my data for my masters thesis at the University of Waterloo.

Thank you!
Sarah

__
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] plspm package error in data frame

2017-06-11 Thread Bert Gunter
You need to first go through a basic tutorial to learn basic R
constructs and functionality. IMHO, fooling around with special
packages before you learn the basics is a bad strategy. Packages
generally assume you know the basics.

Some tutorial recommendations can be found here:

https://www.rstudio.com/online-learning/

But just googling around the web will turn up lots of alternatives.
Choose what suits you best.


Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Jun 11, 2017 at 12:16 PM, Sarah Sinasac  wrote:
> Hello,
> I am new to R and hope I will not seem ignorant in this post. I am
> currently using the plspm package by Gaston Sanchez accompanied by his
> text book.
> I have attempted to create a square matrix, which has seemed
> successful. I used the following code:
>
>> "Attitude" = c(1, 0, 0, 0, 0, 0, 0, 0)
>
>> "Normative Beliefs" = c(1, 0, 0, 0, 0, 0, 0, 0)
>
>> "Subjective Norm" = c(0, 0, 1, 0, 0, 0, 0, 0)
>
>> "Control Beliefs" = c(1, 0, 1, 0, 0, 0, 0, 0)
>
>> "Perceived Behavioural Control" = c(0, 0, 0, 0, 1, 0, 0, 0)
>
>> "Intention" = c(0, 1, 0, 1, 0, 1, 0, 0)
>
>> "Behaviour" = c(0, 0, 0, 0, 0, 0, 1, 0)
>
>> TPB_path = rbind(`Behavioural Beliefs`, Attitude, `Normative Beliefs`, 
>> `Subjective Norm`, `Control Beliefs`, `Perceived Behavioural Control`, 
>> Intention, Behaviour)
>
>> colnames(TPB_path) = rownames(TPB_path)
>
>> innerplot(TPB_path, box.size = 0.1)
>
> Then I attempted to set up the pls model using the following code (as
> directed by the textbook and the r help function):
>
>> #outermodel
>
>> TPB_blocks = list(1:7, 8:14, 15:21, 22:28, 29:34, 35:39, 40:44, 45:48)
>
>> TPB_modes = rep("A", 8)
>
>> TPB_pls1 = plspm(TPBDATA, TPB_path, TPB_blocks, modes = TPB_modes)
>
> However, I received the following error (I tried multiple times, and
> cannot determine what the error is):
>
> Error in `[.data.frame`(crossloadings, , c("name", "block", 
> colnames(xloads))) :
>
>   undefined columns selected
>
>
> I would really appreciate if anyone could provide advice on how to
> correct this error. I am using the plspm package in order to analyze
> my data for my masters thesis at the University of Waterloo.
>
> Thank you!
> Sarah
>
> __
> 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.


[R] plspm package error in data frame

2017-06-11 Thread Sarah Sinasac
Hello,
I am new to R and hope I will not seem ignorant in this post. I am
currently using the plspm package by Gaston Sanchez accompanied by his
text book.
I have attempted to create a square matrix, which has seemed
successful. I used the following code:

> "Attitude" = c(1, 0, 0, 0, 0, 0, 0, 0)

> "Normative Beliefs" = c(1, 0, 0, 0, 0, 0, 0, 0)

> "Subjective Norm" = c(0, 0, 1, 0, 0, 0, 0, 0)

> "Control Beliefs" = c(1, 0, 1, 0, 0, 0, 0, 0)

> "Perceived Behavioural Control" = c(0, 0, 0, 0, 1, 0, 0, 0)

> "Intention" = c(0, 1, 0, 1, 0, 1, 0, 0)

> "Behaviour" = c(0, 0, 0, 0, 0, 0, 1, 0)

> TPB_path = rbind(`Behavioural Beliefs`, Attitude, `Normative Beliefs`, 
> `Subjective Norm`, `Control Beliefs`, `Perceived Behavioural Control`, 
> Intention, Behaviour)

> colnames(TPB_path) = rownames(TPB_path)

> innerplot(TPB_path, box.size = 0.1)

Then I attempted to set up the pls model using the following code (as
directed by the textbook and the r help function):

> #outermodel

> TPB_blocks = list(1:7, 8:14, 15:21, 22:28, 29:34, 35:39, 40:44, 45:48)

> TPB_modes = rep("A", 8)

> TPB_pls1 = plspm(TPBDATA, TPB_path, TPB_blocks, modes = TPB_modes)

However, I received the following error (I tried multiple times, and
cannot determine what the error is):

Error in `[.data.frame`(crossloadings, , c("name", "block", colnames(xloads))) :

  undefined columns selected


I would really appreciate if anyone could provide advice on how to
correct this error. I am using the plspm package in order to analyze
my data for my masters thesis at the University of Waterloo.

Thank you!
Sarah

__
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] remove

2017-06-11 Thread Jeff Newmiller
The usual way I filter is:

KL$Dt <- as.Date( KL$date, format='%d-%m-%y' )
KL2 <- KL[ !is.na( KL$Dt ), ]

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

On June 10, 2017 10:17:52 PM PDT, Jeff Newmiller  
wrote:
>You are using a slash in your format string to separate sub-fields but
>your data uses a dash.

__
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] errror al determinar puntos óptimos de corte (librería: OptimalCutpoints)

2017-06-11 Thread Fernando Sanchez via R-help-es
Hola Freddy Omar,
Efectivamente, así funciona y es lo que necesitaba. Muchísimas gracias.

  De: Freddy Omar López Quintero 
 Para: Fernando Sanchez  
CC: Lista R. 
 Enviado: Sábado 10 de junio de 2017 23:36
 Asunto: Re: [R-es] errror al determinar puntos óptimos de corte (librería: 
OptimalCutpoints)
   

2017-06-10 11:51 GMT-04:00 Fernando Sanchez via R-help-es 
:

library(OptimalCutpoints) prediccion<-c(0.49165923,0. 52759793,0.30213400,0. 
33468349,0.14979703,0. 47401846,0.52216404,0. 42018794,0.92168073,0. 
76893929,0.83362668,0. 38251162,0.70803701,0. 49165923,0.94462558)
real<-c(0,1,0,0,0,0,1,1,1,1,1, 0,1,0,1)datos_OPTIMO<-cbind( prediccion,real)
cutpoint1 <- optimal.cutpoints(X = "prediccion", status = "real",tag.healthy = 
1, methods = "Youden", data = datos_OPTIMO,categorical.cov =NULL, pop.prev = 
NULL,control = control.cutpoints(), ci.fit = TRUE)

​Creo que el detalle está en que tus datos son una matriz y no un data.frame.​ 
Añadiendo:


datos_OPTIMO<-data.frame(datos_OPTIMO)


a tu código, obtengo:


​> cutpoint1


Call:
optimal.cutpoints.default(X = "prediccion", status = "real", 
    tag.healthy = 1, methods = "Youden", data = datos_OPTIMO, 
    categorical.cov = NULL, pop.prev = NULL, control = control.cutpoints(), 
    ci.fit = TRUE)

Optimal cutoffs:
  Youden
1 0.1498


Ignoro si es lo que se espera de respuesta.

¡Salud!

-- 
«Pídeles sus títulos a los que te persiguen, pregúntales
cuándo nacieron, diles que te demuestren su existencia.»
Rafael Cadenas



   
[[alternative HTML version deleted]]

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