#7 14 7 V2
#8 17 8 V3
#9 20 9 V2
#10 19 10 V3
A.K.
- Original Message -
From: jeff6868
To: r-help@r-project.org
Cc:
Sent: Wednesday, September 26, 2012 6:49 AM
Subject: [R] create new column in a DF according to values from another colu
Hello,
'if' is not vectorized, it only uses the first value of the multiple
condition. 'ifelse' is vectorized and in your case use nested ifelses.
DF <- data.frame(number=c(1,4,7,3,11,16,14,17,20,19),data=c(1:10))
v1 <- c(1,7,11,16)
v2 <- c(4,14,20)
v3 <- c(3,17,19)
DF$Station <- ifelse(DF$n
Yes this is it!
Thank you for your help Berend!
--
View this message in context:
http://r.789695.n4.nabble.com/create-new-column-in-a-DF-according-to-values-from-another-column-tp4644217p4644225.html
Sent from the R help mailing list archive at Nabble.com.
Here is another technique to use, especially if you have a long list
of replacement values:
> DF <- data.frame(number=c(1,4,7,3,11,16,14,17,20,19),data=c(1:10))
>
> # create a list of replacement values; if you have a lot and
> # you can create them automagically, then it is easier
> replace <- l
On 26-09-2012, at 12:49, jeff6868 wrote:
> Hi everyone,
>
> I have a small problem in my R-code.
>
> Imagine this DF for example:
>
> DF <- data.frame(number=c(1,4,7,3,11,16,14,17,20,19),data=c(1:10))
>
> I would like to add a new column "Station" in this DF. This new column must
> be automa
Hi everyone,
I have a small problem in my R-code.
Imagine this DF for example:
DF <- data.frame(number=c(1,4,7,3,11,16,14,17,20,19),data=c(1:10))
I would like to add a new column "Station" in this DF. This new column must
be automatically filled with: "V1" or "V2" or "V3".
The choice must be do
6 matches
Mail list logo