Note that there are some explanatory texts on larger screens.

plurals
  1. POR: NAs introduced by coercion in data frame
    primarykey
    data
    text
    <p>I have a data frame that I build with data from an sql db. First column contains date, the other contain double or string which should be double.</p> <p>I need to convert the string to real double.</p> <p>I have tried to extract the data with "numbers" in another data frame and then: as.numeric or class = numeric.</p> <p>Both those options return error.</p> <p>Any idea?</p> <p>Many thanks, Vincent</p> <p>edit: here is the function where I got my issue/</p> <pre><code> function(Best,Worst,PriceTable){ PnL=data.frame() #PnL long for(i in 1:(nrow(Best)-1)){PnL[i,1]=Best[i+1,1];pnl=0;divide=0;for (j in 1:ncol(Best)){if((!is.null(PriceTable[i+1,as.character(Best[i,j])])) &amp;&amp; (!is.na(as.numeric(PriceTable[i+1,as.character(Best[i,j])])))){pnl=pnl+as.numeric(PriceTable[i+1,as.character(Best[i,j])]);divide=divide+1}};PnL[i,2]=pnl/divide;PnL[i,3]=0;PnL[i,4]=divide} #PnL short for(i in 1:(nrow(Worst)-1)){pnl=0;divide=0;for (j in 1:ncol(Worst)){if((!is.null(PriceTable[i+1,as.character(Worst[i,j])])) &amp;&amp; (!is.na(as.numeric(PriceTable[i+1,as.character(Worst[i,j])])))){pnl=pnl+as.numeric(PriceTable[i+1,as.character(Worst[i,j])]);divide=divide+1}};PnL[i,3]=-pnl/divide;PnL[i,5]=divide} colnames(PnL)[1]='Date' colnames(PnL)[2]='PnL Long' colnames(PnL)[3]='PnL Short' colnames(PnL)[4]='N trade long' colnames(PnL)[5]='N trade short' #overall PnL for (i in 1:nrow(PnL)){PnL[i,6]=PnL[i,3]+PnL[i,2]} colnames(PnL)[6]='PnL' return(PnL) </code></pre> <p>}</p> <p>My TablePrice look (in bigger) like:</p> <pre><code>row.names Date 25179M103 371532102 186905105 382388106 16 2011-01-25 0.08094573 0.001366867 -0.08003574 0.02431649 21 2011-02-01 0.10623324 0.033948941 0.02128497 0.02949376 40 2011-03-01 0.02046414 -0.028119508 -0.16465137 -0.09292013 63 2011-04-01 0.04486064 0.034553366 0.01336088 0.02603872 83 2011-05-02 -0.02220955 -0.016687422 -0.07369759 0.03656137 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload