Skip to content

update cells

4 messages · Daniel, Jeff Ryan, Konrad Hoppe +1 more

#
Not a Finance question. Please follow the posting guidelines and redirect to R-help

Jeff
Sent via BlackBerry from T-Mobile

-----Original Message-----
From: Daniel <dmsilv at gmail.com>
Date: Thu, 17 Jun 2010 08:34:16 
To: <r-sig-finance at stat.math.ethz.ch>
Subject: [R-SIG-Finance] update cells

Hello all,I have a table with about 18000 rows, I need to UPDATE the strings
in the "name.x" column in each row by the strings from "name.y" given if
"name.x" is NA or " ". How can I do it?
Also I want to update values in other columns, but I think that will be the
same job.
Daniel


_______________________________________________
R-SIG-Finance at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
#
As long as there is an answer on the list,
I'll take the liberty of showing what I
think is a better answer.

* The 'for' loop is not very R-ish.

* If the name columns are factors, you are
probably in trouble.

myTable <- data.frame(name_x=c('a', ' ', 'c', NA),
    name_y=LETTERS[1:4], stringsAsFactors=FALSE)

myTable2 <- within(myTable, name_x <-
    ifelse(is.na(name_x) | name_x == " ", name_y, name_x))
On 17/06/2010 23:05, Konrad Hoppe wrote: