Re: [R] data frame question

From: joseph <jdsandjd_at_yahoo.com>
Date: Thu, 14 Feb 2008 15:34:38 -0800 (PST)


Thanks. I have another question:
In the following data frame df, I want to replace all values in col1 that are higher than 3 with NA.
df= data.frame(col1=c(1:5, NA),col2= c(2,NA,4:7))

Create
the
new
data.frame
and
do
the
muliplying
on
it?

df2
<-
df1
df2[,1]
<-
df2[,1]*2

---
joseph
<jdsandjd_at_yahoo.com>
wrote:

>
>
>

Hi
>
>

I
have
a
data

frame
df1
in
which
I
would
like
to
>

multiply
col1
>

by
2.
>
>
>

The
way
I
did
it
does
not
allow
me
to
keep
the
old
>

data
>

frame.
>
>
>

How
can
I
do
this
and
be
able
to
create
a
new
data
>

frame
>

df2?
>
>
>
>

df1=
data.frame(col1=
c(3,
5,
NA,
1),
col2=
c(4,
>

NA,6,
>

2))
>
>
>
>

df1
>
>
>
 

col1
col2
>
>
>

1   

3   

4
>
>
>

2   

5  

NA
>
>
>

3  

NA   

6
>
>
>

4   

1   

2
>
>
>
>

df1$col1=df1$col1*2
>
>
>
>

df1
>
>
>
 

col1
col2
>
>
>

1   

6   

4
>
>
>

2  

10  

NA
>
>
>

3  

NA   

6
>
>
>

4   

2   

2
>
>
>
>
>
>
     

>



>

Be
a
better
friend,
newshound,
and
>
>
>
    

[[alternative
HTML
version
deleted]]
>
>



>

R-help_at_r-project.org
mailing
list
>

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.
>
        

Connect
with
friends
from
any
web
browser
-
no
download
required.
Try
the
new

Canada
Messenger
for
the
Web
BETA
at



Looking for last minute shopping deals?

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
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. Received on Thu 14 Feb 2008 - 23:38:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 15 Feb 2008 - 07:30:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive