[R] Converting character to numeric using the package "XLConnect"

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Thu Aug 31 06:43:37 CEST 2017


All elements of a vector must be of the same type.

Rephrasing: You cannot change one element of a character vector to a numeric value. The numeric value WILL be converted into character before it is put into the target element. 
-- 
Sent from my phone. Please excuse my brevity.

On August 30, 2017 9:01:03 PM PDT, Nelly Reduan <nell.redu at hotmail.fr> wrote:
>Thanks very much for your answer.
>
>I�m trying the function �strtoi� but it fails to convert character to
>numeric after the command "set[index] <- strtoi(set[index])".
>
>
>> strtoi(set[index]) ## This works: all values are numeric !!!
>
>[1] 1 2 3 4 2 8 9 7
>
>
>
>> set[index] <- strtoi(set[index])
>
>
>
>> print(set[10,1]) ## Problem: must be numeric !!!!
>
>[1] "1"
>
>
>
>Thanks very much for your help.
>Nell
>
>
>________________________________
>De : Jim Lemon <drjimlemon at gmail.com>
>Envoy� : mercredi 30 ao�t 2017 15:00:32
>� : Nelly Reduan; r-help mailing list
>Objet : Re: [R] Converting character to numeric using the package
>"XLConnect"
>
>Hi Nelly,
>Are you trying to convert hexadecimal to decimal?
>
> nrdf
>      Setting Value
>1  Parameters     a
>2  Parameters     b
>3  Parameters     c
>4  Parameters     d
>5  Parameters     e
>6  Parameters     2
>7  Parameters     8
>8  Parameters     9
>9  Parameters     7
>10          1     a
>11          2     b
>12          3     c
>13          4     d
>
>strtoi(nrdf$Value,16)
> [1] 10 11 12 13 14  2  8  9  7 10 11 12 13
>
>Jim
>
>On Thu, Aug 31, 2017 at 6:30 AM, Nelly Reduan <nell.redu at hotmail.fr>
>wrote:
>> The Excel file can be found from this link:
>https://1drv.ms/x/s!Apkg2VlgfYyDgQ_mcJ8F4CaXV_Nh
>
>	[[alternative HTML version deleted]]



More information about the R-help mailing list