Setting elements in data frame
Hello, what about converting the data.frame to a matrix? x <- data.matrix(x) x[x==6] <- 6000 x <- as.data.frame(x) x S1 N1 N2 1 2 2 6000 2 3 4 NA 3 4 6000 0 4 1 9 6000 best, jan
On Thu, 22 Feb 2001, Christian Hoffmann wrote:
Hi all,
I have a problem which I am biting my teeth into unsuccessfully:
(x <- data.frame(S1=c("a","b","d","F"),N1=c(2,4,6,9),N2=c(6,NA,0,6)))
S1 N1 N2
1 a 2 6
2 b 4 NA
3 d 6 0
4 F 9 6
is.na(x)
S1 N1 N2 1 FALSE FALSE FALSE 2 FALSE FALSE TRUE 3 FALSE FALSE FALSE 4 FALSE FALSE FALSE No I want to be able to do: 1) Setting all elements == 6 to 6000 x[x == 6] <- 6000 Error in [<-.data.frame(*tmp*, x == 6, value = 6000) : matrix subscripts not allowed in replacement
+----------------------------------- Jan Goebel (mailto:jgoebel at diw.de) DIW Berlin Longitudinal Data and Microanalysis K?nigin-Luise-Str. 5 D-14195 Berlin -- Germany -- phone: 49 30 89789-377 +----------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._