[R] The "condition has length > 1" issue for lists

Svempa fempa at yahoo.com
Mon Oct 15 11:36:58 CEST 2007


I have the following code:

list1 <- list()
for (i in list.files(pattern="filename1")){
    x <- read.table(i)
	list1[[i]] <- x
}

list2 <- list()
for (i in list.files(pattern="filename2*")){
    x <- read.table(i)
	list2[[i]] <- x
}

anslist <- vector('list', length(list1)) 
for(i in 1:length(list1)) 
if (list1[[i]] & list2[[i]] >1)
anslist[[i]] <- list1[[i]] - list2[[i]]

That, if at least one element in either of the lists is below 1, nothing
happens. I now get the warning message "the condition has length >1..." etc.
I would guess this is because list1 and list2 aren't really real matrices,
more references to files. How do I get around this?

-- 
View this message in context: http://www.nabble.com/The-%22condition-has-length-%3E-1%22-issue-for-lists-tf4625785.html#a13209531
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list