Skip to content

How to replace range of data in a dataframe

2 messages · Camilo Mora, jim holtman

#
Hi:
I wonder if anyone may know the answer to this question:

COnsider the following data frame (DF):

ColumnA   ColumnB   ColumnC
   a         d         d
   s         s         e
   e         r         e
   y         w         y
   t         u         i
   q         e         l

What I need is to replace rows 1 to 3 in ColunmC for a random number?
I tried DF$ColumnC[DF$ColumnC [1:3]] <- .Random.seed[1:3]
but does not work.

It may be trivial but have not been able to find a solution.

Thanks,
Camilo
#
Is this what you want:
+  a         d         d
+  s         s         e
+  e         r         e
+  y         w         y
+  t         u         i
+  q         e         l", as.is = TRUE, header = TRUE)
ColumnA ColumnB           ColumnC
1       a       d 0.965288798790425
2       s       s 0.722888228250667
3       e       r 0.634451690129936
4       y       w                 y
5       t       u                 i
6       q       e                 l
Now ColumnC is character, so the random numbers are character strings.
 What is the problem you are trying to solve?
On Wed, Feb 15, 2012 at 4:38 AM, Camilo Mora <cmora at dal.ca> wrote: